Changeset 12311 for code/branches
- Timestamp:
- Apr 18, 2019, 4:05:35 PM (6 years ago)
- 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 97 97 ClickableObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction) 98 98 { 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; 101 102 } 102 103 ScrollableElementID MouseAPI::addScrollElement(const Vector3& position, float radius, std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction) 103 104 { 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; 106 108 } 107 109 ScrollableElementID MouseAPI::addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction) 108 110 { 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; 111 114 } 112 115 -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc
r12306 r12311 35 35 // set factor to 120% or 80% of the current size, depending on increase or decrease 36 36 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; 37 39 //scale the sphere with this factor and change the radius 38 40 this->setScale(factor); 39 41 MouseAPI::getInstance().changeRadiusOfScrollableElement(sphereid,factor*10); 42 } 43 44 // 45 void MouseAPIExample::clickleft(MouseButtonCode::ByEnum mouse) 46 { 47 //MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,10); 48 orxout() << "left" << "\n"; 49 } 50 51 // 52 void MouseAPIExample::clickright(MouseButtonCode::ByEnum mouse) 53 { 54 //MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,10); 55 orxout() << "right" << "\n"; 40 56 } 41 57 … … 57 73 sphereid = MouseAPI::getInstance().addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);}); 58 74 } 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 } 59 81 60 82 // activate MouseAPI -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h
r12306 r12311 18 18 void changesizeonclick(MouseButtonCode::ByEnum mouse); 19 19 void changesizeonscroll(int abs,int rel,const IntVector2& mousePos); 20 void clickleft(MouseButtonCode::ByEnum mouse); 21 void clickright(MouseButtonCode::ByEnum mouse); 20 22 inline void setId(int id) 21 23 { this->id = id; } … … 26 28 ClickableObjectID cubeid; 27 29 ScrollableElementID sphereid; 28 static std::list<MouseAPIExample> blocks;30 ClickableObjectID leftid,rightid; 29 31 }; 30 32 }
Note: See TracChangeset
for help on using the changeset viewer.