7 #include "scene2D/adaptor/SViewportInteractor.hpp" 9 #include <fwRenderQt/Scene2DGraphicsView.hpp> 11 #include <fwServices/macros.hpp> 20 SViewportInteractor::SViewportInteractor() noexcept :
21 m_viewportIsTranslated(false)
27 SViewportInteractor::~SViewportInteractor() noexcept
59 if ( _event.getType() == ::fwRenderQt::data::Event::MouseWheelUp
60 && _event.getModifier() == ::fwRenderQt::data::Event::ShiftModifier )
64 else if ( _event.getType() == ::fwRenderQt::data::Event::MouseWheelDown
65 && _event.getModifier() == ::fwRenderQt::data::Event::ShiftModifier )
69 else if ( _event.getType() == ::fwRenderQt::data::Event::MouseButtonPress
70 && _event.getButton() == ::fwRenderQt::data::Event::LeftButton
71 && _event.getModifier() == ::fwRenderQt::data::Event::ShiftModifier )
73 m_viewportIsTranslated =
true;
74 m_lastCoordEvent = _event.getCoord();
76 else if ( m_viewportIsTranslated )
78 if ( _event.getType() == ::fwRenderQt::data::Event::MouseMove )
81 ::fwRenderQt::data::Viewport::sptr sceneViewport = this->
getScene2DRender()->getViewport();
83 const float dx = coord.getX() - m_lastCoordEvent.getX();
84 const float xTrans = dx * sceneViewport->getWidth() / (float) this->
getScene2DRender()->getView()->width();
86 const float dy = coord.getY() - m_lastCoordEvent.getY();
87 const float yTrans = dy * sceneViewport->getHeight() /
90 sceneViewport->setX( sceneViewport->getX() - xTrans );
91 sceneViewport->setY( sceneViewport->getY() - yTrans );
94 m_lastCoordEvent = coord;
96 else if ( _event.getType() == ::fwRenderQt::data::Event::MouseButtonRelease )
98 m_viewportIsTranslated =
false;
105 void SViewportInteractor::zoom(
bool zoomIn )
107 ::fwRenderQt::data::Viewport::sptr sceneViewport = this->
getScene2DRender()->getViewport();
109 float y = sceneViewport->getY();
110 float x = sceneViewport->getX();
112 float width = sceneViewport->getWidth();
113 float height = sceneViewport->getHeight();
115 const float zoomPercent = 10.f / 100.0f;
116 const float centerX = x + width/2.0f;
117 const float centerY = y + height/2.0f;
123 newWidth = width * zoomPercent;
124 newHeight = height * zoomPercent;
128 newWidth = -width * zoomPercent;
129 newHeight = -height * zoomPercent;
135 x = centerX - newWidth / 2;
136 y = centerY - newHeight / 2;
142 sceneViewport->setX( x );
143 sceneViewport->setY( y );
144 sceneViewport->setWidth( width );
145 sceneViewport->setHeight( height );
Root class for all scene2d adaptors.
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
This bundles contains data and services used to display a 2D Qt scene.
SCENE2D_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
Adaptor implementation that manages the camera on the view.
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
SCENE2D_API void starting() override
Initialize the service activity.
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.
This class manage events on the scene 2D (mouse event, keyboard event , ...).