- Timestamp:
- Oct 29, 2008, 11:55:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.cc
r2023 r2046 56 56 OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator) 57 57 : BaseObject(creator) 58 , overlay_(0)59 , background_(0)60 58 { 61 59 RegisterObject(OrxonoxOverlay); 60 61 // add this overlay to the static map of OrxonoxOverlays 62 if (overlays_s.find(this->getName()) != overlays_s.end()) 63 { 64 COUT(1) << "Overlay names should be unique or you cannnot access them via console." << std::endl; 65 } 66 overlays_s[this->getName()] = this; 67 68 // create the Ogre::Overlay 69 overlay_ = Ogre::OverlayManager::getSingleton().create("OrxonoxOverlay_overlay_" 70 + convertToString(hudOverlayCounter_s++)); 71 72 // create background panel (can be used to show any picture) 73 this->background_ = static_cast<Ogre::PanelOverlayElement*>( 74 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", 75 "OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++))); 76 this->overlay_->add2D(this->background_); 77 78 // We'll have to get the aspect ratio manually for the first time. Afterwards windowResized() gets 79 // called automatically by GSGraphics. 80 this->windowAspectRatio_ = Ogre::OverlayManager::getSingleton().getViewportAspectRatio(); 81 this->sizeCorrectionChanged(); 82 83 this->changedVisibility(); 84 85 setSize(Vector2(1.0f, 1.0f)); 86 setPickPoint(Vector2(0.0f, 0.0f)); 87 setPosition(Vector2(0.0f, 0.0f)); 88 setRotation(Degree(0.0)); 89 setAspectCorrection(true); 90 setBackgroundMaterial(""); 62 91 } 63 92 … … 70 99 OrxonoxOverlay::~OrxonoxOverlay() 71 100 { 72 // erase ourself from the map with all overlays 73 std::map<std::string, OrxonoxOverlay*>::iterator it = overlays_s.find(this->getName()); 74 if (it != overlays_s.end()) 75 overlays_s.erase(it); 76 77 if (this->background_) 101 if (this->isInitialized()) 102 { 103 // erase ourself from the map with all overlays 104 std::map<std::string, OrxonoxOverlay*>::iterator it = overlays_s.find(this->getName()); 105 if (it != overlays_s.end()) 106 overlays_s.erase(it); 107 78 108 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->background_); 79 if (this->overlay_)80 109 Ogre::OverlayManager::getSingleton().destroy(this->overlay_); 110 } 81 111 } 82 112 … … 94 124 SUPER(OrxonoxOverlay, XMLPort, xmlElement, mode); 95 125 96 if (mode == XMLPort::LoadObject) 97 { 98 // add this overlay to the static map of OrxonoxOverlays 99 if (overlays_s.find(this->getName()) != overlays_s.end()) 100 { 101 COUT(1) << "Overlay names should be unique or you cannnot access them via console." << std::endl; 102 } 103 overlays_s[this->getName()] = this; 104 105 // create the Ogre::Overlay 106 overlay_ = Ogre::OverlayManager::getSingleton().create("OrxonoxOverlay_overlay_" 107 + convertToString(hudOverlayCounter_s++)); 108 109 // create background panel (can be used to show any picture) 110 this->background_ = static_cast<Ogre::PanelOverlayElement*>( 111 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", 112 "OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++))); 113 this->overlay_->add2D(this->background_); 114 115 // We'll have to get the aspect ratio manually for the first time. Afterwards windowResized() gets 116 // called automatically by GSGraphics. 117 //this->windowResized(GraphicsEngine::getInstance().getWindowWidth(), 118 // GraphicsEngine::getInstance().getWindowHeight()); 119 this->windowAspectRatio_ = Ogre::OverlayManager::getSingleton().getViewportAspectRatio(); 120 this->sizeCorrectionChanged(); 121 122 this->changedVisibility(); 123 } 124 125 XMLPortParam(OrxonoxOverlay, "size", setSize, getSize, xmlElement, mode) 126 .defaultValues(Vector2(1.0f, 1.0f)); 127 XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode) 128 .defaultValues(Vector2(0.0f, 0.0f)); 129 XMLPortParam(OrxonoxOverlay, "position", setPosition, getPosition, xmlElement, mode) 130 .defaultValues(Vector2(0.0f, 0.0f)); 131 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode) 132 .defaultValues(0.0f); 133 XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode) 134 .defaultValues(true); 135 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode) 136 .defaultValues(""); 126 XMLPortParam(OrxonoxOverlay, "size", setSize, getSize, xmlElement, mode); 127 XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode); 128 XMLPortParam(OrxonoxOverlay, "position", setPosition, getPosition, xmlElement, mode); 129 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode); 130 XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode); 131 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode); 137 132 } 138 133
Note: See TracChangeset
for help on using the changeset viewer.