iMSTK
Interactive Medical Simulation Toolkit
imstkMouseControl.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkMouseControl.h"
8 #include "imstkMouseDeviceClient.h"
9 
10 namespace imstk
11 {
12 void
13 MouseControl::setDevice(std::shared_ptr<DeviceClient> device)
14 {
15  // Remove old observer if it exists
16  if (m_deviceClient != nullptr)
17  {
18  disconnect(m_deviceClient, shared_from_this(), &MouseDeviceClient::mouseButtonPress);
19  disconnect(m_deviceClient, shared_from_this(), &MouseDeviceClient::mouseButtonRelease);
20  disconnect(m_deviceClient, shared_from_this(), &MouseDeviceClient::mouseScroll);
21  disconnect(m_deviceClient, shared_from_this(), &MouseDeviceClient::mouseMove);
22  }
23 
24  // Set the new device
25  m_mouseDevice = std::dynamic_pointer_cast<MouseDeviceClient>(device);
26  DeviceControl::setDevice(device);
27 
28  // Subscribe to the device clients events
29  connect(device, &MouseDeviceClient::mouseButtonPress, shared_from_this(), &MouseControl::mouseButtonPressEvent);
30  connect(device, &MouseDeviceClient::mouseButtonRelease, shared_from_this(), &MouseControl::mouseButtonReleaseEvent);
31  connect(device, &MouseDeviceClient::mouseScroll, shared_from_this(), &MouseControl::mouseScrollEvent);
32  connect(device, &MouseDeviceClient::mouseMove, shared_from_this(), &MouseControl::mouseMoveEvent);
33 }
34 
35 void
36 MouseControl::mouseButtonPressEvent(MouseEvent* e)
37 {
38  OnButtonPress(e->m_buttonId);
39 }
40 
41 void
42 MouseControl::mouseButtonReleaseEvent(MouseEvent* e)
43 {
44  OnButtonRelease(e->m_buttonId);
45 }
46 
47 void
48 MouseControl::mouseScrollEvent(MouseEvent* e)
49 {
50  OnScroll(e->m_scrollDx);
51 }
52 
53 void
54 MouseControl::mouseMoveEvent(MouseEvent* imstkNotUsed(e))
55 {
56  OnMouseMove(m_mouseDevice->getPos());
57 }
58 } // namespace imstk
friend void disconnect(std::shared_ptr< EventObject >, std::shared_ptr< EventObject >, std::string(*)())
Remove an observer from the sender.
Compound Geometry.