Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 28, 2008, 10:55:49 PM (16 years ago)
Author:
rgrieder
Message:

Added minimal test files for a statistics overlay.

Location:
code/branches/overlay/src/orxonox
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/overlay/src/orxonox/gamestates/GSLevel.cc

    r1887 r2036  
    5858        , startLevel_(0)
    5959        , hud_(0)
     60        , stats_(0)
    6061    {
    6162        RegisterObject(GSLevel);
     
    9394        hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
    9495        Loader::load(hud_);
     96
     97        // Load statistics
     98        COUT(3) << "Orxonox: Loading statistics overlay" << std::endl;
     99        stats_ = new Level(Settings::getDataPath() + "overlay/stats.oxo");
     100        Loader::load(stats_);
    95101
    96102        // reset game speed to normal
     
    115121        Loader::unload(hud_);
    116122        delete this->hud_;
     123
     124        Loader::unload(stats_);
     125        delete this->stats_;
    117126
    118127        // this call will delete every BaseObject!
  • code/branches/overlay/src/orxonox/gamestates/GSLevel.h

    r1887 r2036  
    7070        Level*                startLevel_;       //!< current hard coded default level
    7171        Level*                hud_;              //!< 'level' object fo the HUD
     72        Level*                stats_;            //!< 'level' object fo the stats overlay
    7273
    7374        // config values
  • code/branches/overlay/src/orxonox/overlays/OrxonoxOverlay.cc

    r1755 r2036  
    6060    {
    6161        RegisterObject(OrxonoxOverlay);
     62
     63        // add this overlay to the static map of OrxonoxOverlays
     64        if (overlays_s.find(this->getName()) != overlays_s.end())
     65        {
     66            COUT(1) << "Overlay names should be unique or you cannnot access them via console." << std::endl;
     67        }
     68        overlays_s[this->getName()] = this;
     69
     70        // create the Ogre::Overlay
     71        overlay_ = Ogre::OverlayManager::getSingleton().create("OrxonoxOverlay_overlay_"
     72            + convertToString(hudOverlayCounter_s++));
     73
     74        // create background panel (can be used to show any picture)
     75        this->background_ = static_cast<Ogre::PanelOverlayElement*>(
     76            Ogre::OverlayManager::getSingleton().createOverlayElement("Panel",
     77            "OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++)));
     78        this->overlay_->add2D(this->background_);
     79
     80        // We'll have to get the aspect ratio manually for the first time. Afterwards windowResized() gets
     81        // called automatically by the GraphicsEngine.
     82        this->windowResized(GraphicsEngine::getInstance().getWindowWidth(),
     83            GraphicsEngine::getInstance().getWindowHeight());
     84
     85        this->changedVisibility();
    6286    }
    6387
     
    93117    {
    94118        SUPER(OrxonoxOverlay, XMLPort, xmlElement, mode);
    95 
    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         }
    122119
    123120        XMLPortParam(OrxonoxOverlay, "size",      setSize,      getSize,      xmlElement, mode)
  • code/branches/overlay/src/orxonox/overlays/OverlayText.cc

    r1784 r2036  
    3131
    3232#include <OgreOverlayManager.h>
    33 #include <OgreTextAreaOverlayElement.h>
    3433#include <OgrePanelOverlayElement.h>
    3534
     
    4645    {
    4746        RegisterObject(OverlayText);
     47
     48        this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
     49            .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
     50        this->text_->setCharHeight(1.0);
     51
     52        this->background_->addChild(this->text_);
    4853    }
    4954
    5055    OverlayText::~OverlayText()
    5156    {
    52         if (this->text_)
     57        if (this->isInitialized())
    5358            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_);
    5459    }
     
    5762    {
    5863        SUPER(OverlayText, XMLPort, xmlElement, mode);
    59 
    60         if (mode == XMLPort::LoadObject)
    61         {
    62             this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    63                 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
    64             this->text_->setCharHeight(1.0);
    65 
    66             this->background_->addChild(this->text_);
    67         }
    6864
    6965        XMLPortParam(OverlayText, "font",     setFont,     getFont,     xmlElement, mode).defaultValues("Monofur");
     
    7470    void OverlayText::setFont(const std::string& font)
    7571    {
    76         if (this->text_ && font != "")
     72        if (font != "")
    7773            this->text_->setFontName(font);
    7874    }
     
    8076    const std::string& OverlayText::getFont() const
    8177    {
    82         if (this->text_)
    83             return this->text_->getFontName();
    84         else
    85             return blankString;
     78        return this->text_->getFontName();
    8679    }
    8780
  • code/branches/overlay/src/orxonox/overlays/OverlayText.h

    r1625 r2036  
    3434#include <string>
    3535#include <OgrePrerequisites.h>
     36#include <OgreTextAreaOverlayElement.h>
    3637#include "OrxonoxOverlay.h"
    3738
     
    4647        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    4748
    48     protected:
    49         virtual void sizeChanged();
    50 
    51         void setCaption(const std::string& caption) { this->caption_ = caption; }
    52         const std::string& getCaption() const       { return this->caption_; }
     49        void setCaption(const std::string& caption) { this->text_->setCaption(caption); }
     50        std::string getCaption() const              { return this->text_->getCaption(); }
    5351
    5452        void setFont(const std::string& font);
     
    5856        float getTextSize() const    { return this->getSize().y; }
    5957
    60         Ogre::TextAreaOverlayElement* text_;
     58    protected:
     59        virtual void sizeChanged();
    6160
    6261    private:
    63         std::string caption_;
     62
     63        Ogre::TextAreaOverlayElement* text_;
    6464    };
    6565}
  • code/branches/overlay/src/orxonox/overlays/debug/DebugFPSText.cc

    r1755 r2036  
    5050    {
    5151        float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond();
    52         this->text_->setCaption(this->getCaption() + convertToString(fps));
     52        this->setCaption(convertToString(fps));
    5353    }
    5454}
  • code/branches/overlay/src/orxonox/overlays/debug/DebugRTRText.cc

    r1755 r2036  
    5050    {
    5151        float rtr = GraphicsEngine::getInstance().getAverageTickTime();
    52         this->text_->setCaption(this->getCaption() + convertToString(rtr));
     52        this->setCaption(convertToString(rtr));
    5353    }
    5454}
Note: See TracChangeset for help on using the changeset viewer.