| 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 | |
|---|
| 19 | namespace orxonox |
|---|
| 20 | { |
|---|
| 21 | |
|---|
| 22 | typedef uint ClickableObjectID; |
|---|
| 23 | typedef uint ScrollableElementID; |
|---|
| 24 | |
|---|
| 25 | class MouseAPI : public InputHandler, public Singleton<MouseAPI> |
|---|
| 26 | { |
|---|
| 27 | friend class Singleton<MouseAPI>; |
|---|
| 28 | private: |
|---|
| 29 | |
|---|
| 30 | struct clickableElement |
|---|
| 31 | { |
|---|
| 32 | ClickableObjectID id; |
|---|
| 33 | Vector3 position; |
|---|
| 34 | float radius; |
|---|
| 35 | std::list<MouseButtonCode::ByEnum> buttons; |
|---|
| 36 | std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction; |
|---|
| 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){} |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | struct scrollElement |
|---|
| 42 | { |
|---|
| 43 | ScrollableElementID id; |
|---|
| 44 | bool considerPosition; |
|---|
| 45 | Vector3 position; |
|---|
| 46 | float radius; |
|---|
| 47 | std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction; |
|---|
| 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){} |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | static MouseAPI* singletonPtr_s; |
|---|
| 55 | std::list<clickableElement> clickEvents; |
|---|
| 56 | std::list<scrollElement> scrollEvents; |
|---|
| 57 | Ogre::Camera *cam ; |
|---|
| 58 | //IntVector2 mousePos; |
|---|
| 59 | InputState* state; |
|---|
| 60 | bool active = false; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | public: |
|---|
| 65 | |
|---|
| 66 | MouseAPI(); |
|---|
| 67 | ~MouseAPI(); |
|---|
| 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; |
|---|
| 73 | |
|---|
| 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); |
|---|
| 77 | |
|---|
| 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); |
|---|
| 85 | |
|---|
| 86 | void activate(); |
|---|
| 87 | static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;} |
|---|
| 88 | void deactivate(); |
|---|
| 89 | }; |
|---|
| 90 | } |
|---|
| 91 | #endif // MOUSEAPI_H |
|---|