Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 4, 2019, 3:28:50 PM (5 years ago)
Author:
tkuonen
Message:

Begin extending MouseAPI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12263 r12271  
    11#include "mouseapi.h"
     2#include "core/singleton/ScopedSingletonIncludes.h"
     3namespace orxonox{
    24
    3 namespace orxonox{
     5ManageScopedSingleton(MouseAPI, ScopeID::GRAPHICS, false);
    46
    57MouseAPI::MouseAPI()
     
    1012void MouseAPI::activate()
    1113{
     14    active = true;
    1215     if(InputManager::exists())
    1316     {
     
    2326void MouseAPI::deactivate()
    2427{
     28    active = false;
    2529    if(InputManager::exists())
    2630    {
     
    2933        InputManager::getInstance().destroyState("MouseAPI");
    3034    }
     35    clickEvents.clear();
     36    scrollEvents.clear();
    3137}
    3238
     
    3844void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)
    3945{
    40     cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
     46    cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();//todo: trycatch
    4147    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
    4248    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
     
    5763void MouseAPI::mouseScrolled(int abs, int rel)
    5864{
     65    cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
    5966    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
    6067    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
    6168    for(auto event:scrollEvents){
    6269        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
    63             (*(event.onScrolledFunction))(abs,rel,mousePos);
     70            event.onScrolledFunction(abs,rel,mousePos);
    6471    }
    6572}
    6673
    67 void MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
     74ClickableObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
    6875{
    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;
    7078}
    71 void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
     79ScrollableElementID MouseAPI::addScrollElement(const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction)
    7280{
    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;
    7483}
    75 void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
     84ScrollableElementID MouseAPI::addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction)
    7685{
    77     scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction});
     86    scrollEvents.insert(scrollEvents.begin(),{!scrollEvents.empty() ? scrollEvents.back().id + 1:0,onScrolledFunction});
     87    return scrollEvents.back().id;
    7888}
    7989
    80 void MouseAPI::changeCamera(Camera& camera)
    81 {
    82     cam = camera.getOgreCamera();
    83 }
     90//todo
     91void MouseAPI::changePositionOfClickableObject(ClickableObjectID id,const Vector3& position){}
     92void MouseAPI::changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position){}
     93void MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius){}
     94void MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius){}
     95void MouseAPI::deleteClickableObject(ClickableObjectID){}
     96void MouseAPI::deleteScrollableElement(ScrollableElementID){}
    8497
    8598}
Note: See TracChangeset for help on using the changeset viewer.