This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit 47d39e5b227fece6fa6e47c65e385a4377ba8e6e Author: krzys-h <krzy...@interia.pl> Date: Sun Feb 14 15:51:18 2016 +0100 Right click camera; minor CCamera cleanups --- src/common/event.h | 10 --- src/graphics/engine/camera.cpp | 180 +++++++++++++---------------------------- src/graphics/engine/camera.h | 24 ++---- src/level/robotmain.cpp | 1 - src/object/old_object.cpp | 1 - src/ui/controls/control.cpp | 2 +- src/ui/controls/edit.cpp | 2 +- src/ui/controls/interface.cpp | 8 +- src/ui/controls/interface.h | 2 - src/ui/controls/list.cpp | 17 ++-- src/ui/controls/map.cpp | 13 +-- src/ui/controls/target.cpp | 2 +- src/ui/controls/window.cpp | 2 +- 13 files changed, 87 insertions(+), 177 deletions(-) diff --git a/src/common/event.h b/src/common/event.h index 362fb09..50fb0c9 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -637,16 +637,6 @@ struct MouseButtonEventData : public EventData }; /** - * \enum WheelDirection - * \brief Direction of mouse wheel movement - */ -enum WheelDirection -{ - WHEEL_UP, - WHEEL_DOWN -}; - -/** * \struct MouseWheelEventData * \brief Additional data for mouse wheel event. */ diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 60a48bf..41796a4 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -98,11 +98,6 @@ CCamera::CCamera() m_normLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_focus = 1.0f; - m_rightDown = false; - m_rightPosInit = Math::Point(0.5f, 0.5f); - m_rightPosCenter = Math::Point(0.5f, 0.5f); - m_rightPosMove = Math::Point(0.5f, 0.5f); - m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); m_directionH = 0.0f; m_directionV = 0.0f; @@ -130,12 +125,6 @@ CCamera::CCamera() m_remotePan = 0.0f; - m_mouseDirH = 0.0f; - m_mouseDirV = 0.0f; - m_mouseMarging = 0.01f; - - m_motorTurn = 0.0f; - m_centeringPhase = CAM_PHASE_NULL; m_centeringAngleH = 0.0f; m_centeringAngleV = 0.0f; @@ -222,13 +211,6 @@ bool CCamera::GetCameraInvertY() return m_cameraInvertY; } -float CCamera::GetMotorTurn() -{ - if (m_type == CAM_TYPE_BACK) - return m_motorTurn; - return 0.0f; -} - void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) { m_initDelay = delay; @@ -1076,6 +1058,11 @@ bool CCamera::EventProcess(const Event &event) EventFrame(event); break; + case EVENT_MOUSE_BUTTON_DOWN: + case EVENT_MOUSE_BUTTON_UP: + EventMouseButton(event); + break; + case EVENT_MOUSE_MOVE: EventMouseMove(event); break; @@ -1092,7 +1079,10 @@ bool CCamera::EventProcess(const Event &event) bool CCamera::EventMouseMove(const Event &event) { + m_mouseDelta += (event.mousePos - m_mousePos); m_mousePos = event.mousePos; + if (m_mouseRightDown) + m_engine->SetMouseType(ENG_MOUSE_MOVE); return true; } @@ -1129,6 +1119,24 @@ void CCamera::EventMouseWheel(const Event &event) } } +void CCamera::EventMouseButton(const Event &event) +{ + if (event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_RIGHT) + { + if (event.type == EVENT_MOUSE_BUTTON_DOWN) + { + m_mouseRightDown = true; + m_mouseDelta.LoadZero(); + m_engine->SetMouseType(ENG_MOUSE_MOVE); + } + else + { + m_mouseRightDown = false; + m_engine->SetMouseType(ENG_MOUSE_NORM); + } + } +} + bool CCamera::EventFrame(const Event &event) { EffectFrame(event); @@ -1168,69 +1176,6 @@ bool CCamera::EventFrame(const Event &event) return true; } -EngineMouseType CCamera::GetMouseDef(Math::Point pos) -{ - EngineMouseType type = ENG_MOUSE_NORM; - m_mousePos = pos; - - if (m_type == CAM_TYPE_INFO) - return type; - - if (m_rightDown) // the right button pressed? - { - m_rightPosMove.x = pos.x - m_rightPosCenter.x; - m_rightPosMove.y = pos.y - m_rightPosCenter.y; - type = ENG_MOUSE_MOVE; - } - else - { - if (!m_cameraScroll) - return type; - - m_mouseDirH = 0.0f; - m_mouseDirV = 0.0f; - - if (pos.x < m_mouseMarging) - m_mouseDirH = pos.x / m_mouseMarging - 1.0f; - - if (pos.x > 1.0f - m_mouseMarging) - m_mouseDirH = 1.0f - (1.0f - pos.x) / m_mouseMarging; - - if (pos.y < m_mouseMarging) - m_mouseDirV = pos.y / m_mouseMarging - 1.0f; - - if (pos.y > 1.0f-m_mouseMarging) - m_mouseDirV = 1.0f - (1.0f - pos.y) / m_mouseMarging; - - if ( m_type == CAM_TYPE_FREE || - m_type == CAM_TYPE_EDIT || - m_type == CAM_TYPE_BACK || - m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE || - m_type == CAM_TYPE_EXPLO ) - { - if (m_mouseDirH > 0.0f) - type = ENG_MOUSE_SCROLLR; - if (m_mouseDirH < 0.0f) - type = ENG_MOUSE_SCROLLL; - } - - if ( m_type == CAM_TYPE_FREE || - m_type == CAM_TYPE_EDIT ) - { - if (m_mouseDirV > 0.0f) - type = ENG_MOUSE_SCROLLU; - if (m_mouseDirV < 0.0f) - type = ENG_MOUSE_SCROLLD; - } - - if (m_cameraInvertX) - m_mouseDirH = -m_mouseDirH; - } - - return type; -} - bool CCamera::EventFrameFree(const Event &event) { Math::Vector cameraInput = event.cameraInput; @@ -1241,10 +1186,12 @@ bool CCamera::EventFrameFree(const Event &event) float factor = m_heightEye * 0.5f + 30.0f; - if ( m_mouseDirH != 0.0f ) - m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed; - if ( m_mouseDirV != 0.0f ) - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed); + if ( m_mouseRightDown ) + { + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); + m_mouseDelta.LoadZero(); + } // Up/Down m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, cameraInput.y * event.rTime * factor * m_speed); @@ -1314,17 +1261,13 @@ bool CCamera::EventFrameEdit(const Event &event) { float factor = m_editHeight * 0.5f + 30.0f; - if (m_mouseDirH != 0.0f) - m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed; - if (m_mouseDirV != 0.0f) - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed); - - if (m_cameraScroll) + if (m_mouseRightDown) { - // Left/Right. - m_fixDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed; - m_fixDirectionH = Math::NormAngle(m_fixDirectionH); + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); + m_mouseDelta.LoadZero(); } + m_fixDirectionH = Math::NormAngle(m_fixDirectionH); m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1377,25 +1320,13 @@ bool CCamera::EventFrameBack(const Event &event) if (m_backDist > 200.0f) m_backDist = 200.0f; } - m_motorTurn = 0.0f; - - if (m_rightDown) - { - m_addDirectionH = m_rightPosMove.x * 6.0f; - m_addDirectionV = -m_rightPosMove.y * 2.0f; - } - else + if (m_mouseRightDown) { - if (m_cameraScroll) - { - // Left/Right - m_addDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed; - m_addDirectionH = Math::NormAngle(m_addDirectionH); - } - } - - if ((m_mouseDirH != 0) || (m_mouseDirV != 0)) + m_addDirectionH -= m_mouseDelta.x * 2*Math::PI; + m_addDirectionH = Math::NormAngle(m_addDirectionH); + m_mouseDelta.LoadZero(); AbortCentering(); // special stops framing + } // Increase the special framework float centeringH = 0.0f; @@ -1528,21 +1459,21 @@ bool CCamera::EventFrameFix(const Event &event) if (m_fixDist > 200.0f) m_fixDist = 200.0f; } - // Left/Right - if (m_cameraScroll) + if (m_mouseRightDown) { - m_fixDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed; - m_fixDirectionH = Math::NormAngle(m_fixDirectionH); + m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI; + m_mouseDelta.LoadZero(); + AbortCentering(); // special stops framing } + + // Left/Right m_fixDirectionH += event.cameraInput.x * event.rTime * 0.7f * m_speed; + m_fixDirectionH = Math::NormAngle(m_fixDirectionH); // Up/Down m_fixDirectionV -= event.cameraInput.y * event.rTime * 0.7f * m_speed; m_fixDirectionV = Math::Min(Math::Max(m_fixDirectionV, -0.5*Math::PI), 0.25*Math::PI); - if ((m_mouseDirH != 0) || (m_mouseDirV != 0)) - AbortCentering(); // special stops framing - if (m_cameraObj != nullptr) { Math::Vector lookatPt = m_cameraObj->GetPosition(); @@ -1567,8 +1498,11 @@ bool CCamera::EventFrameFix(const Event &event) bool CCamera::EventFrameExplo(const Event &event) { - if (m_mouseDirH != 0.0f) - m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed; + if (m_mouseRightDown) + { + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_mouseDelta.LoadZero(); + } m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1649,9 +1583,10 @@ bool CCamera::EventFrameVisit(const Event &event) if (m_visitDirectionV > 0.0f ) m_visitDirectionV = 0.0f; } - if (m_cameraScroll) + if (m_mouseRightDown) { - m_visitDist -= m_mouseDirV * event.rTime * 30.0f * m_speed; + m_visitDist -= m_mouseDelta.y * 100.0f * m_speed; + m_mouseDelta.LoadZero(); if (m_visitDist < 20.0f) m_visitDist = 20.0f; if (m_visitDist > 200.0f) m_visitDist = 200.0f; } @@ -1744,5 +1679,4 @@ void CCamera::SetCameraSpeed(float speed) m_speed = speed; } - } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 3161471..0d5c7d7 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -211,18 +211,15 @@ public: void SetCameraInvertY(bool invert); bool GetCameraInvertY(); - //! Returns an additional force to turn - float GetMotorTurn(); - //! Returns the default sprite to use for the mouse - EngineMouseType GetMouseDef(Math::Point pos); - void SetCameraSpeed(float speed); protected: //! Changes the camera according to the mouse moved bool EventMouseMove(const Event &event); //! Mouse wheel operation - void EventMouseWheel(const Event& event); + void EventMouseWheel(const Event &event); + //! Mouse button handling + void EventMouseButton(const Event &event); //! Changes the camera according to the time elapsed bool EventFrame(const Event &event); //! Moves the point of view @@ -301,11 +298,6 @@ protected: float m_focus; - bool m_rightDown; - Math::Point m_rightPosInit; - Math::Point m_rightPosCenter; - Math::Point m_rightPosMove; - //! CAM_TYPE_FREE: eye Math::Vector m_eyePt; //! CAM_TYPE_FREE: horizontal direction @@ -352,12 +344,9 @@ protected: float m_remotePan; - Math::Point m_mousePos; - float m_mouseDirH; - float m_mouseDirV; - float m_mouseMarging; - - float m_motorTurn; + bool m_mouseRightDown = false; + Math::Point m_mousePos = Math::Point(0.5f, 0.5f); + Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f); CenteringPhase m_centeringPhase; float m_centeringAngleH; @@ -396,7 +385,6 @@ protected: bool m_cameraInvertX; //! Y inversion in the edges? bool m_cameraInvertY; - }; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 5791801..d1daf0c 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -687,7 +687,6 @@ bool CRobotMain::ProcessEvent(Event &event) m_displayText->EventProcess(event); RemoteCamera(m_cameraPan, m_cameraZoom, event.rTime); - m_interface->EventProcess(event); if (m_displayInfo != nullptr) // current edition? m_displayInfo->EventProcess(event); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 55343e6..7fd53ca 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -2103,7 +2103,6 @@ bool COldObject::EventProcess(const Event &event) axeZ = -1.0f; // tomb } - axeX += m_camera->GetMotorTurn(); // additional power according to camera if ( axeX > 1.0f ) axeX = 1.0f; if ( axeX < -1.0f ) axeX = -1.0f; diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index d167b08..e0b8ccf 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -314,7 +314,7 @@ bool CControl::EventProcess(const Event &event) GlintFrame(event); } - if ( event.type == EVENT_MOUSE_MOVE ) + if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP ) { m_glintMouse = event.mousePos; diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 481e7c2..2e99cec 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -266,7 +266,7 @@ bool CEdit::EventProcess(const Event &event) m_timeBlink += event.rTime; } - if ( event.type == EVENT_MOUSE_MOVE ) + if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP ) { if ( Detect(event.mousePos) && event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) ) diff --git a/src/ui/controls/interface.cpp b/src/ui/controls/interface.cpp index 6ad3bfc..ad8d6ef 100644 --- a/src/ui/controls/interface.cpp +++ b/src/ui/controls/interface.cpp @@ -54,7 +54,6 @@ CInterface::CInterface() { m_event = CApplication::GetInstancePointer()->GetEventQueue(); m_engine = Gfx::CEngine::GetInstancePointer(); - m_camera = nullptr; } // Object's destructor. @@ -300,12 +299,9 @@ CControl* CInterface::SearchControl(EventType eventMsg) bool CInterface::EventProcess(const Event &event) { - if (event.type == EVENT_MOUSE_MOVE) + if (event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) { - if (m_camera == nullptr) - m_camera = CRobotMain::GetInstancePointer()->GetCamera(); - - m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos)); + m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); } for (auto& control : boost::adaptors::reverse(m_controls)) diff --git a/src/ui/controls/interface.h b/src/ui/controls/interface.h index 5c351e8..264faf3 100644 --- a/src/ui/controls/interface.h +++ b/src/ui/controls/interface.h @@ -29,7 +29,6 @@ namespace Gfx { -class CCamera; class CEngine; } // namespace Gfx @@ -101,7 +100,6 @@ protected: CEventQueue* m_event; Gfx::CEngine* m_engine; - Gfx::CCamera* m_camera; std::array<std::unique_ptr<CControl>, MAXCONTROL> m_controls; }; diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index c23c935..b446bd2 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -293,15 +293,18 @@ bool CList::EventProcess(const Event &event) CControl::EventProcess(event); - if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos)) + if (event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) { - m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); - for (int i = 0; i < m_displayLine; i++) + if (Detect(event.mousePos)) { - if (i + m_firstLine >= m_totalLine) - break; - if (m_buttons[i] != nullptr) - m_buttons[i]->EventProcess(event); + m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); + for (int i = 0; i < m_displayLine; i++) + { + if (i + m_firstLine >= m_totalLine) + break; + if (m_buttons[i] != nullptr) + m_buttons[i]->EventProcess(event); + } } } diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 0bc607d..9bc35b9 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -203,12 +203,15 @@ bool CMap::EventProcess(const Event &event) if ( event.type == EVENT_FRAME ) m_time += event.rTime; - if ( event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos) ) + if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP ) { - m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); - bool inMap = false; - if (DetectObject(event.mousePos, inMap) != nullptr) - m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND); + if (Detect(event.mousePos)) + { + m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); + bool inMap = false; + if (DetectObject(event.mousePos, inMap) != nullptr) + m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND); + } } if (event.type == EVENT_MOUSE_BUTTON_DOWN && diff --git a/src/ui/controls/target.cpp b/src/ui/controls/target.cpp index 1bd7ac7..b42116f 100644 --- a/src/ui/controls/target.cpp +++ b/src/ui/controls/target.cpp @@ -64,7 +64,7 @@ bool CTarget::EventProcess(const Event &event) CControl::EventProcess(event); - if ( event.type == EVENT_MOUSE_MOVE ) + if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP ) { m_main->SetFriendAim(false); diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index 0f4f9ac..8182aaf 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -662,7 +662,7 @@ int CWindow::BorderDetect(Math::Point pos) bool CWindow::EventProcess(const Event &event) { - if ( event.type == EVENT_MOUSE_MOVE ) + if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP ) { if ( m_bCapture ) { -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits