Changeset 12352 for code/branches
- Timestamp:
- May 9, 2019, 2:05:27 PM (6 years ago)
- 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 54 54 ADD_SUBDIRECTORY(wagnis) 55 55 ADD_SUBDIRECTORY(MouseAPI) 56 ADD_SUBDIRECTORY(MouseAPIExample) -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/CMakeLists.txt
r12334 r12352 1 1 SET_SOURCE_FILES(MOUSEAPI_SRC_FILES 2 2 mouseapi.cc 3 mouseapiexample.cc4 3 mousegametype.cc 5 4 mouseapicursor.cc -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12334 r12352 104 104 } 105 105 106 Clickable ObjectID MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)107 { 108 Clickable ObjectID id = !clickEvents.empty() ? clickEvents.back().id + 1:0;106 ClickableElementID 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; 109 109 clickEvents.insert(clickEvents.end(),{id,position,radius,buttons,onClickedFunction}); 110 110 return id; … … 124 124 125 125 126 bool MouseAPI::changePositionOfClickable Object(ClickableObjectID id,const Vector3& position)126 bool MouseAPI::changePositionOfClickableElement(ClickableElementID id,const Vector3& position) 127 127 { 128 128 for(auto event:clickEvents) … … 148 148 return false; 149 149 } 150 bool MouseAPI::changeRadiusOfClickable Object(ClickableObjectID id,float radius)150 bool MouseAPI::changeRadiusOfClickableElement(ClickableElementID id,float radius) 151 151 { 152 152 for(auto event = clickEvents.begin();event != clickEvents.end();event++ ) … … 172 172 return false; 173 173 } 174 bool MouseAPI::deleteClickable Object(ClickableObjectID id)174 bool MouseAPI::deleteClickableElement(ClickableElementID id) 175 175 { 176 176 for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ ) … … 197 197 } 198 198 199 float MouseAPI::getRadiusClick(Clickable ObjectID id)199 float MouseAPI::getRadiusClick(ClickableElementID id) 200 200 { 201 201 for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ ) -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12348 r12352 20 20 #include "tools/interfaces/Tickable.h" 21 21 22 /* This class implements a basic mouse-api22 /* this class implements a basic mouse-api 23 23 * supported are mouse-clicks (left, right, mousewheel, ...) and scrolling 24 24 * … … 30 30 * 31 31 * 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 34 37 */ 35 38 36 39 namespace orxonox 37 40 { 38 typedef uint Clickable ObjectID;41 typedef uint ClickableElementID; 39 42 typedef uint ScrollableElementID; 40 43 … … 47 50 struct clickableElement 48 51 { 49 Clickable ObjectID id;52 ClickableElementID id; 50 53 Vector3 position; 51 54 float radius; 52 55 std::list<MouseButtonCode::ByEnum> buttons; 53 56 std::function<void(MouseButtonCode::ByEnum button)> onClickedFunction; 54 clickableElement(Clickable ObjectID 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), 55 58 radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){} 56 59 }; … … 58 61 /* Elements that can be "scrolled on" are stored as scrollElement 59 62 * there are 2 diffrent types, hence the overloaded constructor: 60 * 1) the function is called whenever one scrolls, independet from position of object and cursor61 * 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) 62 65 */ 63 66 struct scrollElement … … 127 130 * Arguments: 128 131 * 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) 130 133 * buttons: the function will only be called, if one of these buttons is pressed 131 134 * 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 138 144 */ 139 145 ScrollableElementID addScrollElement(const Vector3& position,float radius,std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction); 140 146 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 143 150 */ 144 151 ScrollableElementID addScrollElement(std::function<void(int abs,int rel,const IntVector2& mousePos)> onScrolledFunction); 145 152 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 */ 148 171 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 */ 150 191 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 */ 152 209 bool deleteScrollableElement(ScrollableElementID id); 153 210 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 */ 155 221 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 */ 156 227 Vector2 getMousePosition(); 157 228 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 */ 158 233 void activate(); 234 235 // returns true if MouseAPI is active, false otherwise 159 236 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 */ 160 242 void deactivate(); 161 243 };
Note: See TracChangeset
for help on using the changeset viewer.