[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> |
---|
[12309] | 18 | #include "core/GUIManager.h" |
---|
| 19 | #include "core/input/KeyBinderManager.h" |
---|
[12213] | 20 | |
---|
| 21 | namespace orxonox |
---|
| 22 | { |
---|
| 23 | |
---|
[12271] | 24 | typedef uint ClickableObjectID; |
---|
| 25 | typedef uint ScrollableElementID; |
---|
| 26 | |
---|
| 27 | class MouseAPI : public InputHandler, public Singleton<MouseAPI> |
---|
[12213] | 28 | { |
---|
[12271] | 29 | friend class Singleton<MouseAPI>; |
---|
[12213] | 30 | private: |
---|
| 31 | |
---|
| 32 | struct clickableElement |
---|
| 33 | { |
---|
[12271] | 34 | ClickableObjectID id; |
---|
[12213] | 35 | Vector3 position; |
---|
| 36 | float radius; |
---|
[12247] | 37 | std::list<MouseButtonCode::ByEnum> buttons; |
---|
[12253] | 38 | std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction; |
---|
[12275] | 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){} |
---|
[12213] | 41 | }; |
---|
| 42 | |
---|
| 43 | struct scrollElement |
---|
| 44 | { |
---|
[12271] | 45 | ScrollableElementID id; |
---|
[12213] | 46 | bool considerPosition; |
---|
| 47 | Vector3 position; |
---|
| 48 | float radius; |
---|
[12271] | 49 | std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction; |
---|
[12275] | 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){} |
---|
[12213] | 54 | }; |
---|
| 55 | |
---|
[12271] | 56 | static MouseAPI* singletonPtr_s; |
---|
[12213] | 57 | std::list<clickableElement> clickEvents; |
---|
| 58 | std::list<scrollElement> scrollEvents; |
---|
[12247] | 59 | Ogre::Camera *cam ; |
---|
[12287] | 60 | //IntVector2 mousePos; |
---|
[12217] | 61 | InputState* state; |
---|
[12271] | 62 | bool active = false; |
---|
[12213] | 63 | |
---|
| 64 | |
---|
[12271] | 65 | |
---|
[12213] | 66 | public: |
---|
| 67 | |
---|
[12253] | 68 | MouseAPI(); |
---|
[12213] | 69 | ~MouseAPI(); |
---|
[12217] | 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; |
---|
[12213] | 75 | |
---|
[12271] | 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); |
---|
[12217] | 79 | |
---|
[12275] | 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); |
---|
[12253] | 87 | |
---|
[12302] | 88 | float getRadiusClick(ClickableObjectID id); |
---|
| 89 | float getRadiusScroll(ScrollableElementID id); |
---|
| 90 | |
---|
[12309] | 91 | Vector2 getMousePosition(); |
---|
| 92 | |
---|
[12253] | 93 | void activate(); |
---|
[12271] | 94 | static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;} |
---|
[12253] | 95 | void deactivate(); |
---|
[12213] | 96 | }; |
---|
| 97 | } |
---|
| 98 | #endif // MOUSEAPI_H |
---|