Changeset 12217 for code/branches/MouseAPI_FS19/src
- Timestamp:
- Mar 21, 2019, 4:06:42 PM (6 years ago)
- Location:
- code/branches/MouseAPI_FS19/src/modules/MouseAPI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12213 r12217 1 1 #include "mouseapi.h" 2 2 3 MouseAPI::MouseAPI( )3 MouseAPI::MouseAPI(Camera& camera) 4 4 { 5 cam = camera.getOgreCamera(); 6 state = InputManager::getInstance().createInputState("MouseAPI"); 7 state->setMouseExclusive(false); 8 state->setMouseHandler(this); 9 InputManager::getInstance().enterState("MouseAPI"); 5 10 6 11 } 7 12 8 MouseAPI::~MouseAPI(){} 13 MouseAPI::~MouseAPI(){ 14 //todo look at gslevel destructor and implement this one 15 } 9 16 10 virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button){} 11 virtual void MouseAPI::mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize){} 12 virtual void MouseAPI::mouseScrolled (int abs, int rel){} 17 virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button) 18 { 19 Ogre::Viewport vp = GraphicsManager::getInstance().getViewport(); 20 Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight())); 21 for(auto event: clickEvents) 22 { 23 for(auto wantedButton:buttons){ 24 if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,radius))) 25 (&(event.onClickedFunction))(button); 26 } 27 } 28 } 13 29 14 v oid addClickableObject(const Vector3& position,float radius,const list<ClickEvent>& events,void (*onClickedFunction)())30 virtual void MouseAPI::mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 15 31 { 16 clickEvents.insert({position,radius,events,onClickedFunction});32 mousePos = abs; 17 33 } 18 void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) 34 35 virtual void MouseAPI::mouseScrolled (int abs, int rel) 36 { 37 Ogre::Viewport vp = GraphicsManager::getInstance().getViewport(); 38 Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight())); 39 for(auto event:scrollEvents){ 40 if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,radius))) 41 (*(event.onScrolledFunction))(abs,rel,mousePos); 42 } 43 } 44 45 void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)) 46 { 47 clickEvents.insert({position,radius,buttons,onClickedFunction}); 48 } 49 void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) 19 50 { 20 51 scrollEvents.insert(position,radius,onScrolledFunction); 21 52 } 22 void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos))53 void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) 23 54 { 24 55 scrollEvents.insert(onScrolledFunction); 25 56 } 57 58 void MouseAPI::changeCamera(Camera& camera) 59 { 60 cam = camera.getOgreCamera(); 61 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12213 r12217 5 5 #include <list> 6 6 #include <core/input/InputHandler.h> 7 #include <graphics/Camera.h> 8 #include <core/GraphicsManager.h> 9 #include <core/input/InputState.h> 7 10 8 11 namespace orxonox … … 18 21 Vector3 position; 19 22 float radius; 20 list< ClickEvent> events;21 void (*onClickedFunction)( );22 clickableElement(const Vector3& position,float radius,const list< ClickEvent>& events,void (*onClickedFunction)()):position(position),23 radius(radius), events(events), onClickedFunction(onClickedFunction){}23 list<MouseButtonCode::ByEnum> buttons; 24 void (*onClickedFunction)(MouseButtonCode::ByEnum button); 25 clickableElement(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)()):position(position), 26 radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){} 24 27 }; 25 28 … … 39 42 std::list<clickableElement> clickEvents; 40 43 std::list<scrollElement> scrollEvents; 44 Ogre::Camera cam; 45 IntVector2 mousePos; 46 InputState* state; 41 47 42 48 43 49 public: 44 enum ClickEvent45 {46 rightClick,leftClick,middleCLick47 };48 50 49 MouseAPI( );51 MouseAPI(Camera& cam); 50 52 ~MouseAPI(); 51 virtual void buttonPressed (MouseButtonCode::ByEnum button) ;52 virtual void buttonReleased(MouseButtonCode::ByEnum button) {}53 virtual void buttonHeld (MouseButtonCode::ByEnum button) {}54 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) ;55 virtual void mouseScrolled (int abs, int rel) ;53 virtual void buttonPressed (MouseButtonCode::ByEnum button) override; 54 virtual void buttonReleased(MouseButtonCode::ByEnum button) override{} 55 virtual void buttonHeld (MouseButtonCode::ByEnum button) override{} 56 virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) override; 57 virtual void mouseScrolled (int abs, int rel) override; 56 58 57 void addClickableObject(const Vector3& position,float radius,const list< ClickEvent>& events,void (*onClickedFunction)());59 void addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)); 58 60 void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)); 59 61 void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)); 62 63 void changeCamera(Camera& camera); 60 64 }; 61 65 }
Note: See TracChangeset
for help on using the changeset viewer.