Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12311 was 12309, checked in by tkuonen, 6 years ago

Add first version of mousecursor

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