Index: /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
===================================================================
--- /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc	(revision 12246)
+++ /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc	(revision 12247)
@@ -1,3 +1,5 @@
 #include "mouseapi.h"
+
+namespace orxonox{
 
 MouseAPI::MouseAPI(Camera& camera)
@@ -12,46 +14,48 @@
 
 MouseAPI::~MouseAPI(){
-    //todo look at gslevel destructor and implement this one
+    InputManager::getInstance().leaveState("MouseAPI");
+    state->setMouseHandler(nullptr);
+    InputManager::getInstance().destroyState("MouseAPI");
 }
 
-virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button)
+void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)
 {
-    Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();
-    Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));
+    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
+    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
     for(auto event: clickEvents)
     {
-        for(auto wantedButton:buttons){
-            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,radius)))
-                (&(event.onClickedFunction))(button);
+        for(auto wantedButton:event.buttons){
+            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
+                (*(event.onClickedFunction))(button);
         }
     }
 }
 
-virtual void MouseAPI::mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
+void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
 {
     mousePos = abs;
 }
 
-virtual void MouseAPI::mouseScrolled (int abs, int rel)
+void MouseAPI::mouseScrolled(int abs, int rel)
 {
-    Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();
-    Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));
+    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
+    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
     for(auto event:scrollEvents){
-        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,radius)))
+        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
             (*(event.onScrolledFunction))(abs,rel,mousePos);
     }
 }
 
-void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
+void MouseAPI::addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
 {
-    clickEvents.insert({position,radius,buttons,onClickedFunction});
+    clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction});
 }
 void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
 {
-    scrollEvents.insert(position,radius,onScrolledFunction);
+    scrollEvents.insert(scrollEvents.begin(),{position,radius,onScrolledFunction});
 }
 void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
 {
-    scrollEvents.insert(onScrolledFunction);
+    scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction});
 }
 
@@ -60,2 +64,4 @@
     cam = camera.getOgreCamera();
 }
+
+}
Index: /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
===================================================================
--- /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h	(revision 12246)
+++ /code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h	(revision 12247)
@@ -2,4 +2,8 @@
 #define MOUSEAPI_H
 
+
+#include "OrxonoxPrereqs.h"
+#include "util/OgreForwardRefs.h"
+#include "graphics/Camera.h"
 #include <util/Math.h>
 #include <list>
@@ -8,4 +12,6 @@
 #include <core/GraphicsManager.h>
 #include <core/input/InputState.h>
+#include <OgreCamera.h>
+#include <OgreViewport.h>
 
 namespace orxonox
@@ -21,7 +27,7 @@
         Vector3 position;
         float radius;
-        list<MouseButtonCode::ByEnum> buttons;
+        std::list<MouseButtonCode::ByEnum> buttons;
         void (*onClickedFunction)(MouseButtonCode::ByEnum button);
-        clickableElement(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)()):position(position),
+        clickableElement(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)):position(position),
             radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
     };
@@ -33,7 +39,7 @@
         float radius;
         void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos);
-        scrollEvents(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false),
+        scrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false),
             onScrolledFunction(onScrolledFunction){}
-        scrollEvents(Vector3& position, float radius, void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(true),
+        scrollElement(const Vector3& position, float radius, void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(true),
             position(position), radius(radius), onScrolledFunction(onScrolledFunction){}
     };
@@ -42,5 +48,5 @@
     std::list<clickableElement> clickEvents;
     std::list<scrollElement> scrollEvents;
-    Ogre::Camera cam;
+    Ogre::Camera *cam ;
     IntVector2 mousePos;
     InputState* state;
@@ -57,5 +63,5 @@
     virtual void mouseScrolled (int abs, int rel) override;
 
-    void addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button));
+    void addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button));
     void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
     void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
