- Timestamp:
- Apr 4, 2019, 3:28:50 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12263 r12271 1 1 #include "mouseapi.h" 2 #include "core/singleton/ScopedSingletonIncludes.h" 3 namespace orxonox{ 2 4 3 namespace orxonox{ 5 ManageScopedSingleton(MouseAPI, ScopeID::GRAPHICS, false); 4 6 5 7 MouseAPI::MouseAPI() … … 10 12 void MouseAPI::activate() 11 13 { 14 active = true; 12 15 if(InputManager::exists()) 13 16 { … … 23 26 void MouseAPI::deactivate() 24 27 { 28 active = false; 25 29 if(InputManager::exists()) 26 30 { … … 29 33 InputManager::getInstance().destroyState("MouseAPI"); 30 34 } 35 clickEvents.clear(); 36 scrollEvents.clear(); 31 37 } 32 38 … … 38 44 void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button) 39 45 { 40 cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); 46 cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();//todo: trycatch 41 47 Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport(); 42 48 Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight())); … … 57 63 void MouseAPI::mouseScrolled(int abs, int rel) 58 64 { 65 cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); 59 66 Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport(); 60 67 Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight())); 61 68 for(auto event:scrollEvents){ 62 69 if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 63 (*(event.onScrolledFunction))(abs,rel,mousePos);70 event.onScrolledFunction(abs,rel,mousePos); 64 71 } 65 72 } 66 73 67 voidMouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)74 ClickableObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction) 68 75 { 69 clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction}); 76 clickEvents.insert(clickEvents.begin(),{!clickEvents.empty() ? clickEvents.back().id + 1:0,position,radius,buttons,onClickedFunction}); 77 return clickEvents.back().id; 70 78 } 71 void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos))79 ScrollableElementID MouseAPI::addScrollElement(const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction) 72 80 { 73 scrollEvents.insert(scrollEvents.begin(),{position,radius,onScrolledFunction}); 81 scrollEvents.insert(scrollEvents.begin(),{!scrollEvents.empty() ? scrollEvents.back().id + 1:0,position,radius,onScrolledFunction}); 82 return scrollEvents.back().id; 74 83 } 75 void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos))84 ScrollableElementID MouseAPI::addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction) 76 85 { 77 scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction}); 86 scrollEvents.insert(scrollEvents.begin(),{!scrollEvents.empty() ? scrollEvents.back().id + 1:0,onScrolledFunction}); 87 return scrollEvents.back().id; 78 88 } 79 89 80 void MouseAPI::changeCamera(Camera& camera) 81 { 82 cam = camera.getOgreCamera(); 83 } 90 //todo 91 void MouseAPI::changePositionOfClickableObject(ClickableObjectID id,const Vector3& position){} 92 void MouseAPI::changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position){} 93 void MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius){} 94 void MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius){} 95 void MouseAPI::deleteClickableObject(ClickableObjectID){} 96 void MouseAPI::deleteScrollableElement(ScrollableElementID){} 84 97 85 98 }
Note: See TracChangeset
for help on using the changeset viewer.