Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12311


Ignore:
Timestamp:
Apr 18, 2019, 4:05:35 PM (6 years ago)
Author:
mkarpf
Message:

example level weiterentwickelt
mousapi addobject korrigiert

Location:
code/branches/MouseAPI_FS19/src/modules/MouseAPI
Files:
3 edited

Legend:

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

    r12309 r12311  
    9797ClickableObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
    9898{
    99     clickEvents.insert(clickEvents.begin(),{!clickEvents.empty() ? clickEvents.back().id + 1:0,position,radius,buttons,onClickedFunction});
    100     return clickEvents.back().id;
     99    ClickableObjectID id = !clickEvents.empty() ? clickEvents.back().id + 1:0;
     100    clickEvents.insert(clickEvents.end(),{id,position,radius,buttons,onClickedFunction});
     101    return id;
    101102}
    102103ScrollableElementID MouseAPI::addScrollElement(const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction)
    103104{
    104     scrollEvents.insert(scrollEvents.begin(),{!scrollEvents.empty() ? scrollEvents.back().id + 1:0,position,radius,onScrolledFunction});
    105     return scrollEvents.back().id;
     105    ScrollableElementID id = !scrollEvents.empty() ? scrollEvents.back().id + 1:0;
     106    scrollEvents.insert(scrollEvents.end(),{id,position,radius,onScrolledFunction});
     107    return id;
    106108}
    107109ScrollableElementID MouseAPI::addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction)
    108110{
    109     scrollEvents.insert(scrollEvents.begin(),{!scrollEvents.empty() ? scrollEvents.back().id + 1:0,onScrolledFunction});
    110     return scrollEvents.back().id;
     111    ScrollableElementID id = !scrollEvents.empty() ? scrollEvents.back().id + 1:0;
     112    scrollEvents.insert(scrollEvents.end(),{id,onScrolledFunction});
     113    return id;
    111114}
    112115
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc

    r12306 r12311  
    3535    // set factor to 120% or 80% of the current size, depending on increase or decrease
    3636    float factor = curRadius/10*(1+rel/600.0);
     37    // return if factor is outside of range [0.5,5] (limit size)
     38    if(factor > 5 || factor < 0.5) return;
    3739    //scale the sphere with this factor and change the radius
    3840    this->setScale(factor);
    3941    MouseAPI::getInstance().changeRadiusOfScrollableElement(sphereid,factor*10);
     42}
     43
     44//
     45void MouseAPIExample::clickleft(MouseButtonCode::ByEnum mouse)
     46{
     47     //MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,10);
     48    orxout() << "left" << "\n";
     49}
     50
     51//
     52void MouseAPIExample::clickright(MouseButtonCode::ByEnum mouse)
     53{
     54     //MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,10);
     55    orxout() << "right" << "\n";
    4056}
    4157
     
    5773        sphereid = MouseAPI::getInstance().addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
    5874    }
     75    else if(this->getId() == 3) // id == 3; long block
     76    {
     77        // add the left and right outermost part of the long block to the list with clickable Objects and define clickleft/clickright to be called
     78        leftid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left,MouseButtonCode::Right},[this](MouseButtonCode::ByEnum mouse){this->clickleft(mouse);});
     79        rightid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left,MouseButtonCode::Right},[this](MouseButtonCode::ByEnum mouse){this->clickright(mouse);});
     80    }
    5981
    6082    // activate MouseAPI
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h

    r12306 r12311  
    1818    void changesizeonclick(MouseButtonCode::ByEnum mouse);
    1919    void changesizeonscroll(int abs,int rel,const IntVector2& mousePos);
     20    void clickleft(MouseButtonCode::ByEnum mouse);
     21    void clickright(MouseButtonCode::ByEnum mouse);
    2022    inline void setId(int id)
    2123        { this->id = id; }
     
    2628    ClickableObjectID cubeid;
    2729    ScrollableElementID sphereid;
    28     static std::list<MouseAPIExample> blocks;
     30    ClickableObjectID leftid,rightid;
    2931};
    3032}
Note: See TracChangeset for help on using the changeset viewer.