Changeset 1595
- Timestamp:
- Jun 12, 2008, 10:42:15 PM (16 years ago)
- Location:
- code/branches/hud
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/bin/hud/hud.oxh
r1590 r1595 1 1 <HUD name="OrxonoxHUD"> 2 <HUDSpeedBar name ="SpeedBar1" s cale=0.35,0.2 scroll=-0.6,-1.0 value=0 />3 <HUDFPSText name="FPSText" s cale = 0.043,0.043 scroll=-0.93,0.9 font="Monofur" caption="Frames per second: " />4 <HUDRTRText name="RTRText" s cale = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " />5 <Navigation name="Navigation" font="Monofur" navmarkersize=0.03,0.03 />2 <HUDSpeedBar name ="SpeedBar1" size=0.35,0.2 scroll=-0.6,-1.0 value=0 /> 3 <HUDFPSText name="FPSText" size = 0.043,0.043 scroll=-0.93,0.9 font="Monofur" caption="Frames per second: " /> 4 <HUDRTRText name="RTRText" size = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " /> 5 <Navigation name="Navigation" correctAspect=true font="Monofur" navmarkersize=0.03,0.03 /> 6 6 </HUD> -
code/branches/hud/src/core/Executor.cc
r1505 r1595 30 30 #include "Executor.h" 31 31 #include "util/Math.h" 32 #include "util/Convert.h" 32 33 #include "Language.h" 33 34 … … 136 137 { 137 138 std::string paramnumber; 138 if (! Convert::ToString(¶mnumber, param))139 if (!convertValue(¶mnumber, param)) 139 140 return (*this); 140 141 -
code/branches/hud/src/core/TclThreadManager.h
r1535 r1595 45 45 namespace orxonox 46 46 { 47 class boost::thread;48 49 47 struct _CoreExport TclInterpreterBundle 50 48 { -
code/branches/hud/src/orxonox/hud/HUDOverlay.cc
r1590 r1595 41 41 HUDOverlay::HUDOverlay() 42 42 : overlay_(0) 43 , windowAspectRatio_(1.0f) 44 , bCorrectAspect_(false) 45 , size_(1.0f) 46 , sizeCorrection_(1.0f) 43 47 { 44 48 RegisterObject(HUDOverlay); … … 54 58 + convertToString(hudOverlayCounter_s++) + "_" + this->getName()); 55 59 56 this->windowWidth_ = GraphicsEngine::getSingleton().getWindowWidth(); 57 this->windowHeight_ = GraphicsEngine::getSingleton().getWindowHeight(); 58 this->windowAspectRatio_ = windowWidth_/(float)windowHeight_; 60 this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), 61 GraphicsEngine::getSingleton().getWindowHeight()); 59 62 } 60 63 61 XMLPortParam(HUDOverlay, "scale", setScale, getScale, xmlElement, mode); 64 XMLPortParam(HUDOverlay, "size", setSize, getSize, xmlElement, mode); 65 XMLPortParam(HUDOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode); 62 66 XMLPortParam(HUDOverlay, "scroll", setScroll, getScroll, xmlElement, mode); 63 67 XMLPortParam(HUDOverlay, "rotation", setRotation, getRotation, xmlElement, mode); … … 68 72 if (!this->isVisible()) 69 73 this->overlay_->hide(); 74 75 this->sizeChanged(); 70 76 } 71 77 } … … 77 83 void HUDOverlay::changedVisibility() 78 84 { 79 80 81 82 83 84 85 85 if (this->overlay_) 86 { 87 if (this->isVisible()) 88 this->overlay_->show(); 89 else 90 this->overlay_->hide(); 91 } 86 92 } 87 93 88 94 void HUDOverlay::windowResized(int newWidth, int newHeight) 89 95 { 90 this->windowWidth_ = newWidth; 91 this->windowHeight_ = newHeight; 92 this->windowAspectRatio_ = windowWidth_/(float)windowHeight_; 96 this->windowAspectRatio_ = newWidth/(float)newHeight; 97 98 this->setAspectCorrection(this->bCorrectAspect_); 99 } 100 101 void HUDOverlay::setAspectCorrection(bool val) 102 { 103 if (val) 104 { 105 // note: this is only an approximation that is mostly valid when the 106 // magnitude of the width is about the magnitude of the height. 107 // Correctly we would have to take the square root of width*height 108 this->sizeCorrection_.x = 2.0 / (this->windowAspectRatio_ + 1.0); 109 this->sizeCorrection_.y = this->windowAspectRatio_ * this->sizeCorrection_.x; 110 } 111 else 112 { 113 this->sizeCorrection_ = Vector2::UNIT_SCALE; 114 } 115 116 this->bCorrectAspect_ = val; 117 this->sizeChanged(); 118 } 119 120 /** 121 @remarks 122 This function can be overriden by any derivative. 123 */ 124 void HUDOverlay::sizeChanged() 125 { 126 this->overlay_->setScale(size_.x * sizeCorrection_.x, size_.x * sizeCorrection_.y); 93 127 } 94 128 -
code/branches/hud/src/orxonox/hud/HUDOverlay.h
r1590 r1595 47 47 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 48 48 49 virtual void changedVisibility(); 49 void setAspectCorrection(bool val); 50 bool getAspectCorrection() { return this->bCorrectAspect_; } 50 51 51 52 /** Sets the scrolling factor of this overlay. */ … … 68 69 69 70 /** Sets the scaling factor of this overlay. */ 70 void setS cale(const Vector2& scale) { overlay_->setScale(scale.x, scale.y); }71 void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); } 71 72 72 /** Gets the current scale value */ 73 Vector2 getScale() const { return Vector2(overlay_->getScaleX(), overlay_->getScaleY()); } 73 /** Gets the current size (not corrected) */ 74 Vector2 getSize() const { return this->size_; } 75 76 /** Gets the current size (corrected) */ 77 Vector2 getActualSize() const { return this->size_ * this->sizeCorrection_; } 78 79 /** Gets the current size correction */ 80 Vector2 getSizeCorrection() const { return this->sizeCorrection_; } 74 81 75 82 /** Scales the overlay */ 76 void scale(Vector2 scale) { overlay_->setScale(overlay_->getScaleX()*scale.x, overlay_->getScaleY()*scale.y); }83 void scale(Vector2 scale) { this->size_ *= scale; this->sizeChanged(); } 77 84 78 85 protected: 79 virtual void windowResized(int newWidth, int newHeight); 86 virtual void changedVisibility(); 87 virtual void sizeChanged(); 88 float getWindowAspectRatio() { return windowAspectRatio_; } 80 89 81 90 Ogre::Overlay* overlay_; 82 float windowAspectRatio_;83 int windowWidth_;84 int windowHeight_;85 91 86 92 private: 93 void windowResized(int newWidth, int newHeight); 94 95 float windowAspectRatio_; 96 bool bCorrectAspect_; 97 Vector2 size_; 98 Vector2 sizeCorrection_; 99 87 100 static unsigned int hudOverlayCounter_s; 88 89 101 }; 90 102 } -
code/branches/hud/src/orxonox/hud/Navigation.cc
r1590 r1595 54 54 , navMarker_(0) 55 55 , aimMarker_(0) 56 , navText_(0) 56 57 , focus_(0) 57 58 { … … 81 82 { 82 83 // create container 83 this->container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer"));84 this->container_->setMetricsMode(Ogre::GMM_RELATIVE);85 this->container_->setLeft(0.0);86 this->container_->setTop(0.0);87 this->container_->setWidth(1.0);88 this->container_->setHeight(1.0);84 container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer")); 85 container_->setMetricsMode(Ogre::GMM_RELATIVE); 86 container_->setLeft(0.0); 87 container_->setTop(0.0); 88 container_->setWidth(1.0); 89 container_->setHeight(1.0); 89 90 90 91 // create nav text 91 this->navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText"));92 this->navText_->setMetricsMode(Ogre::GMM_RELATIVE);93 this->navText_->setPosition(0.0f, 0.0f);94 this->navText_->setCharHeight(0.05f);95 this->navText_->setFontName("Monofur");92 navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText")); 93 navText_->setMetricsMode(Ogre::GMM_RELATIVE); 94 navText_->setPosition(0.0f, 0.0f); 95 navText_->setCharHeight(0.05f); 96 navText_->setFontName("Monofur"); 96 97 97 98 // create nav marker 98 99 navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navMarker")); 99 100 navMarker_->setMetricsMode(GMM_RELATIVE); 100 navMarker_->setDimensions(0.05f, 0.05f);101 101 navMarker_->setMaterialName("Orxonox/NavArrows"); 102 this->navMarkerSize_ = 0.05; 102 103 this->wasOutOfView_ = true; // just a to ensure the material is changed right the first time.. 103 104 … … 105 106 aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_aimMarker")); 106 107 aimMarker_->setMetricsMode(GMM_RELATIVE); 107 aimMarker_->setDimensions(0.05f, 0.05f);108 108 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 109 this->aimMarkerSize_ = 0.04; 109 110 110 111 container_->addChild(navMarker_); … … 121 122 XMLPortParam(Navigation, "navmarkersize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 122 123 XMLPortParam(Navigation, "aimmarkersize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 123 } 124 125 void Navigation::setNavMarkerSize(Vector2 size) 126 { 127 if (this->navMarker_ && size.squaredLength() >= 0.0f) 128 this->navMarker_->setDimensions(size.x, size.y); 129 } 130 131 Vector2 Navigation::getNavMarkerSize() const 132 { 133 if (this->navMarker_) 134 return Vector2(navMarker_->getWidth(), navMarker_->getHeight()); 135 else 136 return Vector2::ZERO; 137 } 138 139 void Navigation::setAimMarkerSize(Vector2 size) 140 { 141 if (this->aimMarker_ && size.squaredLength() >= 0.0f) 142 this->aimMarker_->setDimensions(size.x, size.y); 143 } 144 145 Vector2 Navigation::getAimMarkerSize() const 146 { 147 if (this->aimMarker_) 148 return Vector2(aimMarker_->getWidth(), aimMarker_->getHeight()); 149 else 150 return Vector2::ZERO; 124 125 if (mode == XMLPort::LoadObject) 126 { 127 this->sizeChanged(); 128 } 129 } 130 131 void Navigation::setNavMarkerSize(float size) 132 { 133 this->navMarkerSize_ = size; 134 } 135 136 float Navigation::getNavMarkerSize() const 137 { 138 return this->navMarkerSize_; 139 } 140 141 void Navigation::setAimMarkerSize(float size) 142 { 143 this->aimMarkerSize_ = size; 144 } 145 146 float Navigation::getAimMarkerSize() const 147 { 148 return this->aimMarkerSize_; 151 149 } 152 150 … … 208 206 pos.x = -pos.x; 209 207 pos.y = -pos.y; 210 pos.z = -pos.z;211 208 } 212 209 else … … 366 363 } 367 364 368 void Navigation::windowResized(int newWidth, int newHeight) 369 { 370 HUDOverlay::windowResized(newWidth, newHeight); 371 372 //if (this->navMarker_) 373 // navMarker_->setDimensions(0.05, 0.05); 374 365 void Navigation::sizeChanged() 366 { 367 float xScale = this->getActualSize().x; 368 float yScale = this->getActualSize().y; 369 if (this->navMarker_) 370 navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); 371 if (this->aimMarker_) 372 aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale); 373 if (this->navText_) 374 navText_->setCharHeight(navText_->getCharHeight() * yScale); 375 375 } 376 376 } -
code/branches/hud/src/orxonox/hud/Navigation.h
r1590 r1595 58 58 59 59 protected: 60 virtual void windowResized(int newWidth, int newHeight);60 virtual void sizeChanged(); 61 61 62 62 private: … … 65 65 void updateFocus(); 66 66 67 void setNavMarkerSize( Vector2size);68 Vector2getNavMarkerSize() const;69 void setAimMarkerSize( Vector2size);70 Vector2getAimMarkerSize() const;67 void setNavMarkerSize(float size); 68 float getNavMarkerSize() const; 69 void setAimMarkerSize(float size); 70 float getAimMarkerSize() const; 71 71 void setTextSize(float size); 72 72 float getTextSize() const; … … 75 75 76 76 Ogre::OverlayContainer* container_; //!< Container that holds the navigation elements 77 Ogre::PanelOverlayElement* navMarker_; // the panel used to show the arrow 78 Ogre::PanelOverlayElement* aimMarker_; 79 Ogre::TextAreaOverlayElement* navText_; // displaying distance 77 Ogre::PanelOverlayElement* navMarker_; //!< the panel used to show the arrow and the target marker 78 float navMarkerSize_; //!< One paramter size of the navigation marker 79 Ogre::PanelOverlayElement* aimMarker_; //!< Panel used to show the aim Marker 80 float aimMarkerSize_; //!< One paramter size of the aim marker 81 Ogre::TextAreaOverlayElement* navText_; //!< Text overlay to display the target distance 80 82 std::list<RadarObject*>::iterator it_; 81 83 RadarObject* focus_; // next pointer of linked list -
code/branches/hud/src/util/Convert.h
r1588 r1595 43 43 #include "SubString.h" 44 44 #include "MultiTypeMath.h" 45 #include "String.h" 45 46 46 47 // disable annoying warning about forcing value to boolean … … 320 321 } 321 322 }; 323 324 // convert from string Shortcut 325 template <class ToType> 326 ToType convertFromString(std::string str) 327 { 328 return getConvertedValue<std::string, ToType>(str); 329 } 322 330 323 331 … … 411 419 //////////////////// 412 420 421 // bool to std::string 422 template <> 423 struct ConverterSpecialized<bool, std::string, _Explicit_> 424 { 425 enum { specialized = true }; 426 static bool convert(std::string* output, const bool& input) 427 { 428 if (input) 429 *output = "true"; 430 else 431 *output = "false"; 432 return false; 433 } 434 }; 435 413 436 // Vector2 to std::string 414 437 template <> … … 501 524 //////////////////// 502 525 526 // std::string to bool 527 template <> 528 struct ConverterSpecialized<std::string, bool, _Explicit_> 529 { 530 enum { specialized = true }; 531 static bool convert(bool* output, const std::string& input) 532 { 533 std::string stripped = getLowercase(removeTrailingWhitespaces(input)); 534 if (stripped == "true" || stripped == "on" || stripped == "yes") 535 { 536 *output = true; 537 return true; 538 } 539 else if (stripped == "false" || stripped == "off" || stripped == "no") 540 { 541 *output = false; 542 return true; 543 } 544 545 std::istringstream iss(input); 546 if (iss >> (*output)) 547 return true; 548 else 549 return false; 550 } 551 }; 552 503 553 // std::string to Vector2 504 554 template <> -
code/branches/hud/src/util/String.h
r1505 r1595 70 70 _UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0); 71 71 72 //! The Convert class has some static member functions to convert strings to values and values to strings.73 class _UtilExport Convert74 {75 public:76 /**77 @brief Converts a value of any type to a string.78 @param output The string to write the result in79 @param input The variable to convert80 @return True if the conversion succeded81 82 @example83 float f = 3.14;84 std::string output;85 bool success = Convert::ToString(&output, f);86 */87 template <typename T>88 static bool ToString(std::string* output, T input)89 {90 std::ostringstream oss;91 if (oss << input)92 {93 (*output) = oss.str();94 return true;95 }96 97 return false;98 }99 100 /**101 @brief Converts a value of any type to a string and assigns a defaultvalue if the conversion fails.102 @param output The string to write the result in103 @param input The variable to convert104 @param fallbackString The assigned string if the conversion fails.105 @return True if the conversion succeeded106 107 @example108 float f = 3.14;109 std::string output;110 bool success = Convert::ToString(&output, f, "0.000000");111 */112 template <typename T>113 static bool ToString(std::string* output, T input, const std::string& fallbackString)114 {115 if (Convert::ToString(output, input))116 return true;117 118 (*output) = fallbackString;119 return false;120 }121 122 /**123 @brief Converts a string to a value of any type.124 @param output The variable to assign the result to125 @param input The string to convert126 @return True if the conversion succeeded127 128 @example129 std::string input = "3.14";130 float f;131 bool success = string2Number(&f, input);132 */133 template <typename T>134 static bool FromString(T* output, const std::string& input)135 {136 std::istringstream iss(input);137 if (iss >> (*output))138 return true;139 140 return false;141 }142 143 /**144 @brief Converts a string to a value of any type.145 @param output The variable to assign the result to146 @param input The string to convert147 @param fallbackValue The assigned value if the conversion fails148 @return True if the conversion succeeded149 150 @example151 std::string input = "3.14";152 float f;153 bool success = string2Number(&f, input, 0.000000);154 */155 template <typename T>156 static bool FromString(T* output, const std::string& input, T fallbackValue)157 {158 if (Convert::FromString(output, input))159 return true;160 161 (*output) = fallbackValue;162 return false;163 }164 };165 166 72 #endif /* _Util_String_H__ */
Note: See TracChangeset
for help on using the changeset viewer.