[12213] | 1 | #include "mouseapi.h" |
---|
| 2 | |
---|
[12217] | 3 | MouseAPI::MouseAPI(Camera& camera) |
---|
[12213] | 4 | { |
---|
[12217] | 5 | cam = camera.getOgreCamera(); |
---|
| 6 | state = InputManager::getInstance().createInputState("MouseAPI"); |
---|
| 7 | state->setMouseExclusive(false); |
---|
| 8 | state->setMouseHandler(this); |
---|
| 9 | InputManager::getInstance().enterState("MouseAPI"); |
---|
[12213] | 10 | |
---|
| 11 | } |
---|
| 12 | |
---|
[12217] | 13 | MouseAPI::~MouseAPI(){ |
---|
| 14 | //todo look at gslevel destructor and implement this one |
---|
| 15 | } |
---|
[12213] | 16 | |
---|
[12217] | 17 | virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button) |
---|
| 18 | { |
---|
| 19 | Ogre::Viewport vp = GraphicsManager::getInstance().getViewport(); |
---|
| 20 | Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight())); |
---|
| 21 | for(auto event: clickEvents) |
---|
| 22 | { |
---|
| 23 | for(auto wantedButton:buttons){ |
---|
| 24 | if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,radius))) |
---|
| 25 | (&(event.onClickedFunction))(button); |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | } |
---|
[12213] | 29 | |
---|
[12217] | 30 | virtual void MouseAPI::mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) |
---|
[12213] | 31 | { |
---|
[12217] | 32 | mousePos = abs; |
---|
[12213] | 33 | } |
---|
[12217] | 34 | |
---|
| 35 | virtual void MouseAPI::mouseScrolled (int abs, int rel) |
---|
[12213] | 36 | { |
---|
[12217] | 37 | Ogre::Viewport vp = GraphicsManager::getInstance().getViewport(); |
---|
| 38 | Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight())); |
---|
| 39 | for(auto event:scrollEvents){ |
---|
| 40 | if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,radius))) |
---|
| 41 | (*(event.onScrolledFunction))(abs,rel,mousePos); |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)) |
---|
| 46 | { |
---|
| 47 | clickEvents.insert({position,radius,buttons,onClickedFunction}); |
---|
| 48 | } |
---|
| 49 | void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) |
---|
| 50 | { |
---|
[12213] | 51 | scrollEvents.insert(position,radius,onScrolledFunction); |
---|
| 52 | } |
---|
[12217] | 53 | void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) |
---|
[12213] | 54 | { |
---|
| 55 | scrollEvents.insert(onScrolledFunction); |
---|
| 56 | } |
---|
[12217] | 57 | |
---|
| 58 | void MouseAPI::changeCamera(Camera& camera) |
---|
| 59 | { |
---|
| 60 | cam = camera.getOgreCamera(); |
---|
| 61 | } |
---|