Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h @ 12296

Last change on this file since 12296 was 12287, checked in by tkuonen, 6 years ago

MouseAPI: improve getting mouse pos

File size: 3.6 KB
RevLine 
[12213]1#ifndef MOUSEAPI_H
2#define MOUSEAPI_H
3
[12247]4
5#include "OrxonoxPrereqs.h"
6#include "util/OgreForwardRefs.h"
7#include "graphics/Camera.h"
[12213]8#include <util/Math.h>
9#include <list>
10#include <core/input/InputHandler.h>
[12217]11#include <graphics/Camera.h>
12#include <core/GraphicsManager.h>
13#include <core/input/InputState.h>
[12247]14#include <OgreCamera.h>
15#include <OgreViewport.h>
[12253]16#include "CameraManager.h"
17#include <functional>
[12213]18
19namespace orxonox
20{
21
[12271]22typedef uint ClickableObjectID;
23typedef uint ScrollableElementID;
24
25class MouseAPI : public InputHandler, public Singleton<MouseAPI>
[12213]26{
[12271]27friend class Singleton<MouseAPI>;
[12213]28private:
29
30    struct clickableElement
31    {
[12271]32        ClickableObjectID id;
[12213]33        Vector3 position;
34        float radius;
[12247]35        std::list<MouseButtonCode::ByEnum> buttons;
[12253]36        std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction;
[12275]37        clickableElement(ClickableObjectID id,const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction):id(id),position(position),
38            radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
[12213]39    };
40
41    struct scrollElement
42    {
[12271]43        ScrollableElementID id;
[12213]44        bool considerPosition;
45        Vector3 position;
46        float radius;
[12271]47        std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction;
[12275]48        scrollElement(ScrollableElementID id,std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction):id(id),considerPosition(false),
49            onScrolledFunction(onScrolledFunction){}
50        scrollElement(ScrollableElementID id,const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction):id(id),considerPosition(true),
51            position(position), radius(radius), onScrolledFunction(onScrolledFunction){}
[12213]52    };
53
[12271]54    static MouseAPI* singletonPtr_s;
[12213]55    std::list<clickableElement> clickEvents;
56    std::list<scrollElement> scrollEvents;
[12247]57    Ogre::Camera *cam ;
[12287]58    //IntVector2 mousePos;
[12217]59    InputState* state;
[12271]60    bool active = false;
[12213]61
62
[12271]63
[12213]64public:
65
[12253]66    MouseAPI();
[12213]67    ~MouseAPI();
[12217]68    virtual void buttonPressed (MouseButtonCode::ByEnum button) override;
69    virtual void buttonReleased(MouseButtonCode::ByEnum button)  override{}
70    virtual void buttonHeld    (MouseButtonCode::ByEnum button) override{}
71    virtual void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) override;
72    virtual void mouseScrolled (int abs, int rel) override;
[12213]73
[12271]74    ClickableObjectID addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)>  onClickedFunction);
75    ScrollableElementID addScrollElement(const Vector3& position,float radius,std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction);
76    ScrollableElementID addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction);
[12217]77
[12275]78    //true: success; false: element not found
79    bool changePositionOfClickableObject(ClickableObjectID id,const Vector3& position);
80    bool changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position);
81    bool changeRadiusOfClickableObject(ClickableObjectID id,float radius);
82    bool changeRadiusOfScrollableElement(ScrollableElementID id,float radius);
83    bool deleteClickableObject(ClickableObjectID id);
84    bool deleteScrollableElement(ScrollableElementID id);
[12253]85
86    void activate();
[12271]87    static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;}
[12253]88    void deactivate();
[12213]89};
90}
91#endif // MOUSEAPI_H
Note: See TracBrowser for help on using the repository browser.