Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 4, 2019, 3:59:47 PM (5 years ago)
Author:
tkuonen
Message:

Extend MouseAPI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12271 r12275  
    4949    for(auto event: clickEvents)
    5050    {
    51         for(auto wantedButton:event.buttons){
     51        for(auto wantedButton:event.buttons)
     52        {
    5253            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
    5354                event.onClickedFunction(button);
     
    6667    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
    6768    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
    68     for(auto event:scrollEvents){
     69    for(auto event:scrollEvents)
     70    {
    6971        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
    7072            event.onScrolledFunction(abs,rel,mousePos);
     
    8890}
    8991
    90 //todo
    91 void MouseAPI::changePositionOfClickableObject(ClickableObjectID id,const Vector3& position){}
    92 void MouseAPI::changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position){}
    93 void MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius){}
    94 void MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius){}
    95 void MouseAPI::deleteClickableObject(ClickableObjectID){}
    96 void MouseAPI::deleteScrollableElement(ScrollableElementID){}
     92
     93bool MouseAPI::changePositionOfClickableObject(ClickableObjectID id,const Vector3& position)
     94{
     95    for(auto event:clickEvents)
     96    {
     97        if(event.id == id)
     98        {
     99            event.position = position;
     100            return true;
     101        }
     102    }
     103    return false;
     104}
     105bool MouseAPI::changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position)
     106{
     107    for(auto event:scrollEvents)
     108    {
     109        if(event.id == id)
     110        {
     111            event.position = position;
     112            return true;
     113        }
     114    }
     115    return false;
     116}
     117bool MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius)
     118{
     119    for(auto event:clickEvents)
     120    {
     121        if(event.id == id)
     122        {
     123            event.radius = radius;
     124            return true;
     125        }
     126    }
     127    return false;
     128}
     129bool MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius)
     130{
     131    for(auto event:scrollEvents)
     132    {
     133        if(event.id == id)
     134        {
     135            event.radius = radius;
     136            return true;
     137        }
     138    }
     139    return false;
     140}
     141bool MouseAPI::deleteClickableObject(ClickableObjectID id)
     142{
     143    for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ )
     144    {
     145        if(eventIt->id == id)
     146        {
     147            clickEvents.erase(eventIt);
     148            return true;
     149        }
     150    }
     151    return false;
     152}
     153bool MouseAPI::deleteScrollableElement(ScrollableElementID id)
     154{
     155    for(auto eventIt = scrollEvents.begin();eventIt != scrollEvents.end();eventIt++ )
     156    {
     157        if(eventIt->id == id)
     158        {
     159            scrollEvents.erase(eventIt);
     160            return true;
     161        }
     162    }
     163    return false;
     164}
    97165
    98166}
Note: See TracChangeset for help on using the changeset viewer.