Changeset 6736
- Timestamp:
- Apr 16, 2010, 12:11:57 PM (15 years ago)
- Location:
- code/branches/gamestates2/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestates2/src/libraries/core/GUIManager.cc
r6722 r6736 30 30 #include "GUIManager.h" 31 31 32 #include <boost/bind.hpp> 32 33 #include <memory> 33 34 extern "C" { … … 175 176 { 176 177 assert(guiSystem_); 177 guiSystem_->injectTimePulse(time.getDeltaTime());178 this->protectedCall(boost::bind(&CEGUI::System::injectTimePulse, _1, time.getDeltaTime())); 178 179 } 179 180 … … 298 299 void GUIManager::keyPressed(const KeyEvent& evt) 299 300 { 300 guiSystem_->injectKeyDown(evt.getKeyCode()); 301 guiSystem_->injectChar(evt.getText()); 302 } 301 this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode())); 302 this->protectedCall(boost::bind(&CEGUI::System::injectChar, _1, evt.getText())); 303 } 304 303 305 void GUIManager::keyReleased(const KeyEvent& evt) 304 306 { 305 guiSystem_->injectKeyUp(evt.getKeyCode());307 this->protectedCall(boost::bind(&CEGUI::System::injectKeyUp, _1, evt.getKeyCode())); 306 308 } 307 309 … … 317 319 void GUIManager::buttonPressed(MouseButtonCode::ByEnum id) 318 320 { 319 try 320 { 321 guiSystem_->injectMouseButtonDown(convertButton(id)); 322 } 323 catch (CEGUI::ScriptException& ex) 324 { 325 // We simply ignore the exception and proceed 326 COUT(1) << ex.getMessage() << std::endl; 327 } 321 this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonDown, _1, convertButton(id))); 328 322 } 329 323 … … 339 333 void GUIManager::buttonReleased(MouseButtonCode::ByEnum id) 340 334 { 341 try 342 { 343 guiSystem_->injectMouseButtonUp(convertButton(id)); 344 } 345 catch (CEGUI::ScriptException& ex) 346 { 347 // We simply ignore the exception and proceed 348 COUT(1) << ex.getMessage() << std::endl; 349 } 335 this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonUp, _1, convertButton(id))); 350 336 } 351 337 352 338 void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 353 339 { 354 guiSystem_->injectMousePosition(static_cast<float>(abs.x), static_cast<float>(abs.y)); 355 } 340 this->protectedCall(boost::bind(&CEGUI::System::injectMousePosition, _1, (float)abs.x, (float)abs.y)); 341 } 342 356 343 void GUIManager::mouseScrolled(int abs, int rel) 357 344 { 358 guiSystem_->injectMouseWheelChange(static_cast<float>(rel));345 this->protectedCall(boost::bind(&CEGUI::System::injectMouseWheelChange, _1, (float)rel)); 359 346 } 360 347 … … 393 380 } 394 381 382 /** Executes a CEGUI function normally, but catches CEGUI::ScriptException. 383 When a ScriptException occurs, the error message will be displayed and 384 the program carries on. 385 @remarks 386 The exception behaviour may pose problems if the code is not written 387 exception-safe (and you can forget about that in Lua). The program might 388 be left in an undefined state. But otherwise one script error would 389 terminate the whole program... 390 @note 391 Your life gets easier if you use boost::bind to create the object/function. 392 @param function 393 Any callable object/function that takes this->guiSystem_ as its only parameter. 394 @return 395 True if input was handled, false otherwise. A caught exception yields true. 396 */ 397 template <typename FunctionType> 398 bool GUIManager::protectedCall(FunctionType function) 399 { 400 try 401 { 402 return function(this->guiSystem_); 403 } 404 catch (CEGUI::ScriptException& ex) 405 { 406 // Display the error and proceed. See @remarks why this can be dangerous. 407 COUT(1) << ex.getMessage() << std::endl; 408 return true; 409 } 410 } 411 395 412 void GUIManager::subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function) 396 413 { -
code/branches/gamestates2/src/libraries/core/GUIManager.h
r6722 r6736 101 101 void executeCode(const std::string& str); 102 102 103 template <typename FunctionType> 104 bool protectedCall(FunctionType function); 105 103 106 // keyHandler functions 104 107 void keyPressed (const KeyEvent& evt);
Note: See TracChangeset
for help on using the changeset viewer.