Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12352 for code/branches


Ignore:
Timestamp:
May 9, 2019, 2:05:27 PM (6 years ago)
Author:
mkarpf
Message:

separated MouseAPIExample from MouseAPI

finished comments in MouseAPI.h

Location:
code/branches/MouseAPI_FS19/src/modules
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/src/modules/CMakeLists.txt

    r12213 r12352  
    5454ADD_SUBDIRECTORY(wagnis)
    5555ADD_SUBDIRECTORY(MouseAPI)
     56ADD_SUBDIRECTORY(MouseAPIExample)
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/CMakeLists.txt

    r12334 r12352  
    11SET_SOURCE_FILES(MOUSEAPI_SRC_FILES
    22  mouseapi.cc
    3   mouseapiexample.cc
    43  mousegametype.cc
    54  mouseapicursor.cc
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12334 r12352  
    104104}
    105105
    106 ClickableObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
    107 {
    108     ClickableObjectID id = !clickEvents.empty() ? clickEvents.back().id + 1:0;
     106ClickableElementID MouseAPI::addClickableElement(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
     107{
     108    ClickableElementID id = !clickEvents.empty() ? clickEvents.back().id + 1:0;
    109109    clickEvents.insert(clickEvents.end(),{id,position,radius,buttons,onClickedFunction});
    110110    return id;
     
    124124
    125125
    126 bool MouseAPI::changePositionOfClickableObject(ClickableObjectID id,const Vector3& position)
     126bool MouseAPI::changePositionOfClickableElement(ClickableElementID id,const Vector3& position)
    127127{
    128128    for(auto event:clickEvents)
     
    148148    return false;
    149149}
    150 bool MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius)
     150bool MouseAPI::changeRadiusOfClickableElement(ClickableElementID id,float radius)
    151151{
    152152    for(auto event = clickEvents.begin();event != clickEvents.end();event++ )
     
    172172    return false;
    173173}
    174 bool MouseAPI::deleteClickableObject(ClickableObjectID id)
     174bool MouseAPI::deleteClickableElement(ClickableElementID id)
    175175{
    176176    for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ )
     
    197197}
    198198
    199 float MouseAPI::getRadiusClick(ClickableObjectID id)
     199float MouseAPI::getRadiusClick(ClickableElementID id)
    200200{
    201201     for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ )
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12348 r12352  
    2020#include "tools/interfaces/Tickable.h"
    2121
    22 /* This class implements a basic mouse-api
     22/* this class implements a basic mouse-api
    2323 * supported are mouse-clicks (left, right, mousewheel, ...) and scrolling
    2424 *
     
    3030 *
    3131 * in short the class works by storing every element that can be clicked / scrolled on in a list
    32  * everytime a button is clicked or the mousewheel is turned, the list gets traversed and every element checked wheter it is clicked / scrolled on
    33  * checking happens by casting a ray from the camera through the mouse-cursor and testing wheter it intersects the sphere of the element
     32 * everytime a button is clicked or the mousewheel is turned, the list gets traversed and every element checked if it is clicked / scrolled on
     33 * checking happens by casting a ray from the camera through the mouse-cursor and testing if it intersects the sphere of the element
     34 *
     35 * to make it work, one has to add mouseapi in LINK_LIBRARIES in the file CMakeLists.txt of the level
     36 * see CMakeLists.txt in MouseAPIExample
    3437 */
    3538
    3639namespace orxonox
    3740{
    38 typedef uint ClickableObjectID;
     41typedef uint ClickableElementID;
    3942typedef uint ScrollableElementID;
    4043
     
    4750    struct clickableElement
    4851    {
    49         ClickableObjectID id;
     52        ClickableElementID id;
    5053        Vector3 position;
    5154        float radius;
    5255        std::list<MouseButtonCode::ByEnum> buttons;
    5356        std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction;
    54         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),
     57        clickableElement(ClickableElementID id,const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction):id(id),position(position),
    5558            radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
    5659    };
     
    5861    /* Elements that can be "scrolled on" are stored as scrollElement
    5962     * there are 2 diffrent types, hence the overloaded constructor:
    60      *      1) the function is called whenever one scrolls, independet from position of object and cursor
    61      *      2) the function is only called when the cursor is over the object (same as with a clickElement)
     63     *      1) the function is called whenever one scrolls, independet from position of element and cursor
     64     *      2) the function is only called when the cursor is placed over the element (identical to the clickableElement)
    6265     */
    6366    struct scrollElement
     
    127130     * Arguments:
    128131     *      position: the point that needs to be clicked
    129      *      radius: radius of the sphere around the position, if the cursor is inside this radius, the function will be executed (because clicking on a single point is pretty hard)
     132     *      radius: radius of the sphere around the position; if the cursor is inside this radius, the function will be executed (because clicking on a single point is pretty hard)
    130133     *      buttons: the function will only be called, if one of these buttons is pressed
    131134     *      onClickedFunction: the function that will be called
    132      *
    133      */
    134     ClickableObjectID addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)>  onClickedFunction);
    135 
    136     /*
    137      *
     135     */
     136    ClickableElementID addClickableElement(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,std::function<void(MouseButtonCode::ByEnum button)>  onClickedFunction);
     137
     138    /* add a scrollElement to the list
     139     * see mouseapiexample for an example-implementation
     140     * Arguments:
     141     *      position: the point the cursor needs to be over
     142     *      radius: radius of the sphere around the position; if the cursor is inside this radius, the function will be executed
     143     *      onScrolledFunction: the function that will be called
    138144     */
    139145    ScrollableElementID addScrollElement(const Vector3& position,float radius,std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction);
    140146
    141     /*
    142      *
     147    /* add a scrollElement to the list
     148     * Arguments:
     149     *      onScrolledFunction: the function that will be called, no matter where the cursor is
    143150     */
    144151    ScrollableElementID addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction);
    145152
    146     //true: success; false: element not found
    147     bool changePositionOfClickableObject(ClickableObjectID id,const Vector3& position);
     153    /* change the position of a clickableElement
     154     * Arguments:
     155     *      id: the ClickableElementID of the element
     156     *      position: the new position of the element
     157     * Return:
     158     *      true if successfull
     159     *      false if not successfull
     160     */
     161    bool changePositionOfClickableElement(ClickableElementID id,const Vector3& position);
     162
     163    /* change the position of a scrollElement
     164     * Arguments:
     165     *      id: the ScrollableElementID of the element
     166     *      position: the new position of the element
     167     * Return:
     168     *      true if successfull
     169     *      false if not successfull
     170     */
    148171    bool changePositionOfScrollableElement(ScrollableElementID id,const Vector3& position);
    149     bool changeRadiusOfClickableObject(ClickableObjectID id,float radius);
     172
     173    /* change the radius of a clickableElement
     174     * Arguments:
     175     *      id: the ClickableElementID of the element
     176     *      radius: the new radius of the element
     177     * Return:
     178     *      true if successfull
     179     *      false if not successfull
     180     */
     181    bool changeRadiusOfClickableElement(ClickableElementID id,float radius);
     182
     183    /* change the radius of a scrollElement
     184     * Arguments:
     185     *      id: the ScrollableElementID of the element
     186     *      radius: the new radius of the element
     187     * Return:
     188     *      true if successfull
     189     *      false if not successfull
     190     */
    150191    bool changeRadiusOfScrollableElement(ScrollableElementID id,float radius);
    151     bool deleteClickableObject(ClickableObjectID id);
     192
     193    /* remove a clickableElement
     194     * Arguments:
     195     *      id: the ClickableElementID of the element
     196     * Return:
     197     *      true if successfull
     198     *      false if not successfull
     199     */
     200    bool deleteClickableElement(ClickableElementID id);
     201
     202    /* remove a scrollElement
     203     * Arguments:
     204     *      id: the ScrollableElementID of the element
     205     * Return:
     206     *      true if successfull
     207     *      false if not successfull
     208     */
    152209    bool deleteScrollableElement(ScrollableElementID id);
    153210
    154     float getRadiusClick(ClickableObjectID id);
     211    /* get the current radius of a clickableElement
     212     * Arguments:
     213     *      id: the ClickableElementID of the element
     214     */
     215    float getRadiusClick(ClickableElementID id);
     216
     217    /* get the current radius of a scrollElement
     218     * Arguments:
     219     *      id: the ScrollableElementID of the element
     220     */
    155221    float getRadiusScroll(ScrollableElementID id);
     222
     223    /* get the current relative Position of the cursor
     224     * returns a value between 0 and 1 for both x and y component
     225     * (0,0) top left corner, (1,1) bottom right corner
     226     */
    156227    Vector2 getMousePosition();
    157228
     229    /* activate the MouseAPI
     230     * has to be called after the level has been created (i.e. inside the xml-port
     231     * can be called multiple times, since the function checks the status of MouseAPI and does nothing if it already is active
     232     */
    158233    void activate();
     234
     235    // returns true if MouseAPI is active, false otherwise
    159236    static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;}
     237
     238    /* deactivate the MouseAPI
     239     * has to be called, when the level gets closed (i.e. inside the level-destructor)
     240     * the function does nothing if MouseAPI is not active
     241     */
    160242    void deactivate();
    161243};
Note: See TracChangeset for help on using the changeset viewer.