Changeset 12275 for code/branches/MouseAPI_FS19/src/modules
- Timestamp:
- Apr 4, 2019, 3:59:47 PM (6 years ago)
- 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 49 49 for(auto event: clickEvents) 50 50 { 51 for(auto wantedButton:event.buttons){ 51 for(auto wantedButton:event.buttons) 52 { 52 53 if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 53 54 event.onClickedFunction(button); … … 66 67 Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport(); 67 68 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 { 69 71 if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 70 72 event.onScrolledFunction(abs,rel,mousePos); … … 88 90 } 89 91 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 93 bool 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 } 105 bool 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 } 117 bool 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 } 129 bool 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 } 141 bool 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 } 153 bool 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 } 97 165 98 166 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12271 r12275 30 30 struct clickableElement 31 31 { 32 //static ClickableObjectID lastClID;33 32 ClickableObjectID id; 34 33 Vector3 position; … … 36 35 std::list<MouseButtonCode::ByEnum> buttons; 37 36 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){} 40 39 }; 41 40 42 41 struct scrollElement 43 42 { 44 static ScrollableElementID lastScID;45 43 ScrollableElementID id; 46 44 bool considerPosition; … … 48 46 float radius; 49 47 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){} 54 52 }; 55 53 … … 78 76 ScrollableElementID addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction); 79 77 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); 86 85 87 86 void activate();
Note: See TracChangeset
for help on using the changeset viewer.