Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12275


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

Extend MouseAPI

Location:
code/branches/MouseAPI_FS19/src/modules/MouseAPI
Files:
2 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}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12271 r12275  
    3030    struct clickableElement
    3131    {
    32         //static ClickableObjectID lastClID;
    3332        ClickableObjectID id;
    3433        Vector3 position;
     
    3635        std::list<MouseButtonCode::ByEnum> buttons;
    3736        std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction;
    38         clickableElement(ClickableObjectID id,const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction):position(position),
    39             radius(radius), buttons(buttons), onClickedFunction(onClickedFunction),id(id){}
     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){}
    4039    };
    4140
    4241    struct scrollElement
    4342    {
    44         static ScrollableElementID lastScID;
    4543        ScrollableElementID id;
    4644        bool considerPosition;
     
    4846        float radius;
    4947        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):considerPosition(false),
    51             onScrolledFunction(onScrolledFunction),id(id){}
    52         scrollElement(ScrollableElementID id,const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction):considerPosition(true),
    53             position(position), radius(radius), onScrolledFunction(onScrolledFunction),id(id){}
     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){}
    5452    };
    5553
     
    7876    ScrollableElementID addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction);
    7977
    80     void changePositionOfClickableObject(ClickableObjectID id,const Vector3& position);
    81     void changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position);
    82     void changeRadiusOfClickableObject(ClickableObjectID id,float radius);
    83     void changeRadiusOfScrollableElement(ScrollableElementID id,float radius);
    84     void deleteClickableObject(ClickableObjectID);
    85     void deleteScrollableElement(ScrollableElementID);
     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);
    8685
    8786    void activate();
Note: See TracChangeset for help on using the changeset viewer.