Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (17 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r1755 r2087  
    4444#include "core/XMLPort.h"
    4545#include "core/ConsoleCommand.h"
    46 #include "GraphicsEngine.h"
    4746
    4847namespace orxonox
     
    5554    SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User);
    5655
    57     OrxonoxOverlay::OrxonoxOverlay()
    58         : overlay_(0)
    59         , background_(0)
     56    OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator)
     57        : BaseObject(creator)
    6058    {
    6159        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. Name: \"" << this->getName() << "\"" << 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 set the aspect ratio to a default value first.
     79        // GSGraphics gets informed about our construction here and can update us in the next tick.
     80        this->windowAspectRatio_ = 1.0;
     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("");
    6291    }
    6392
     
    7099    OrxonoxOverlay::~OrxonoxOverlay()
    71100    {
    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
    78108            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->background_);
    79         if (this->overlay_)
    80109            Ogre::OverlayManager::getSingleton().destroy(this->overlay_);
     110        }
    81111    }
    82112
     
    94124        SUPER(OrxonoxOverlay, XMLPort, xmlElement, mode);
    95125
    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 the GraphicsEngine.
    117             this->windowResized(GraphicsEngine::getInstance().getWindowWidth(),
    118                 GraphicsEngine::getInstance().getWindowHeight());
    119 
    120             this->changedVisibility();
    121         }
    122 
    123         XMLPortParam(OrxonoxOverlay, "size",      setSize,      getSize,      xmlElement, mode)
    124             .defaultValues(Vector2(1.0f, 1.0f));
    125         XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode)
    126             .defaultValues(Vector2(0.0f, 0.0f));
    127         XMLPortParam(OrxonoxOverlay, "position",  setPosition,  getPosition,  xmlElement, mode)
    128             .defaultValues(Vector2(0.0f, 0.0f));
    129         XMLPortParam(OrxonoxOverlay, "rotation",  setRotation,  getRotation,  xmlElement, mode)
    130             .defaultValues(0.0f);
    131         XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection,   getAspectCorrection,   xmlElement, mode)
    132             .defaultValues(true);
    133         XMLPortParam(OrxonoxOverlay, "background",    setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode)
    134             .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);
     132    }
     133
     134    void OrxonoxOverlay::changedName()
     135    {
     136        OrxonoxOverlay::overlays_s.erase(this->getOldName());
     137
     138        if (OrxonoxOverlay::overlays_s.find(this->getName()) != OrxonoxOverlay::overlays_s.end())
     139            COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl;
     140
     141        OrxonoxOverlay::overlays_s[this->getName()] = this;
    135142    }
    136143
     
    148155            return this->background_->getMaterialName();
    149156        else
    150             return blankString;
     157            return BLANKSTRING;
    151158    }
    152159
Note: See TracChangeset for help on using the changeset viewer.