Changeset 12253 for code/branches
- Timestamp:
- Mar 28, 2019, 3:32:09 PM (6 years ago)
- Location:
- code/branches/MouseAPI_FS19/src/modules/MouseAPI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/src/modules/MouseAPI/CMakeLists.txt
r12213 r12253 1 1 SET_SOURCE_FILES(MOUSEAPI_SRC_FILES 2 2 mouseapi.cc 3 mouseapiexample.cc 3 4 ) 4 5 -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12247 r12253 3 3 namespace orxonox{ 4 4 5 MouseAPI::MouseAPI( Camera& camera)5 MouseAPI::MouseAPI() 6 6 { 7 cam = camera.getOgreCamera();8 state = InputManager::getInstance().createInputState("MouseAPI");9 state->setMouseExclusive(false);//does this work10 state->setMouseHandler(this);11 InputManager::getInstance().enterState("MouseAPI");12 7 13 8 } 14 9 15 MouseAPI::~MouseAPI(){ 16 InputManager::getInstance().leaveState("MouseAPI"); 17 state->setMouseHandler(nullptr); 18 InputManager::getInstance().destroyState("MouseAPI"); 10 void MouseAPI::activate() 11 { 12 if(InputManager::exists()) 13 { 14 cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); 15 state = InputManager::getInstance().createInputState("MouseAPI"); 16 state->setMouseExclusive(false);//does this work 17 state->setMouseHandler(this); 18 InputManager::getInstance().enterState("MouseAPI"); 19 } 20 21 } 22 23 void MouseAPI::deactivate() 24 { 25 if(InputManager::exists()) 26 { 27 InputManager::getInstance().leaveState("MouseAPI"); 28 state->setMouseHandler(nullptr); 29 InputManager::getInstance().destroyState("MouseAPI"); 30 } 31 } 32 33 MouseAPI::~MouseAPI() 34 { 35 19 36 } 20 37 … … 27 44 for(auto wantedButton:event.buttons){ 28 45 if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 29 (*(event.onClickedFunction))(button);46 event.onClickedFunction(button); 30 47 } 31 48 } … … 47 64 } 48 65 49 void MouseAPI::addClickableObject(const Vector3& position, float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))66 void MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction) 50 67 { 51 68 clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction}); -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12247 r12253 14 14 #include <OgreCamera.h> 15 15 #include <OgreViewport.h> 16 #include "CameraManager.h" 17 #include <functional> 16 18 17 19 namespace orxonox … … 28 30 float radius; 29 31 std::list<MouseButtonCode::ByEnum> buttons; 30 void (*onClickedFunction)(MouseButtonCode::ByEnum button);31 clickableElement(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons, void (*onClickedFunction)(MouseButtonCode::ByEnum button)):position(position),32 std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction; 33 clickableElement(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction):position(position), 32 34 radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){} 33 35 }; … … 55 57 public: 56 58 57 MouseAPI( Camera& cam);59 MouseAPI(); 58 60 ~MouseAPI(); 59 61 virtual void buttonPressed (MouseButtonCode::ByEnum button) override; … … 63 65 virtual void mouseScrolled (int abs, int rel) override; 64 66 65 void addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons, void (*onClickedFunction)(MouseButtonCode::ByEnum button));67 void addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction); 66 68 void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)); 67 69 void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)); 68 70 69 71 void changeCamera(Camera& camera); 72 73 void activate(); 74 void deactivate(); 70 75 }; 71 76 }
Note: See TracChangeset
for help on using the changeset viewer.