Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12253 for code/branches


Ignore:
Timestamp:
Mar 28, 2019, 3:32:09 PM (6 years ago)
Author:
mkarpf
Message:

Test Level created
ATTENTION: Level is buggy and freezes Screen!

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  
    11SET_SOURCE_FILES(MOUSEAPI_SRC_FILES
    22  mouseapi.cc
     3  mouseapiexample.cc
    34)
    45
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12247 r12253  
    33namespace orxonox{
    44
    5 MouseAPI::MouseAPI(Camera& camera)
     5MouseAPI::MouseAPI()
    66{
    7     cam = camera.getOgreCamera();
    8     state = InputManager::getInstance().createInputState("MouseAPI");
    9     state->setMouseExclusive(false);//does this work
    10     state->setMouseHandler(this);
    11     InputManager::getInstance().enterState("MouseAPI");
    127
    138}
    149
    15 MouseAPI::~MouseAPI(){
    16     InputManager::getInstance().leaveState("MouseAPI");
    17     state->setMouseHandler(nullptr);
    18     InputManager::getInstance().destroyState("MouseAPI");
     10void 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
     23void 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
     33MouseAPI::~MouseAPI()
     34{
     35
    1936}
    2037
     
    2744        for(auto wantedButton:event.buttons){
    2845            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
    29                 (*(event.onClickedFunction))(button);
     46                event.onClickedFunction(button);
    3047        }
    3148    }
     
    4764}
    4865
    49 void MouseAPI::addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
     66void MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
    5067{
    5168    clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction});
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12247 r12253  
    1414#include <OgreCamera.h>
    1515#include <OgreViewport.h>
     16#include "CameraManager.h"
     17#include <functional>
    1618
    1719namespace orxonox
     
    2830        float radius;
    2931        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),
    3234            radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
    3335    };
     
    5557public:
    5658
    57     MouseAPI(Camera& cam);
     59    MouseAPI();
    5860    ~MouseAPI();
    5961    virtual void buttonPressed (MouseButtonCode::ByEnum button) override;
     
    6365    virtual void mouseScrolled (int abs, int rel) override;
    6466
    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);
    6668    void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
    6769    void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
    6870
    6971    void changeCamera(Camera& camera);
     72
     73    void activate();
     74    void deactivate();
    7075};
    7176}
Note: See TracChangeset for help on using the changeset viewer.