Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 22, 2008, 12:06:55 AM (17 years ago)
Author:
rgrieder
Message:
  • added blankString to String so you can return ""; even if it's a const std::string&
  • fixed several bugs with aspect correct and margin alignment
  • added console commands for OrxonoxOverlays and OverlayGroups for rotate, scale and scroll (you can access the by name (from name=.. in xml file), e.g. "OrxonoxOverlay rotateOverlay SpeedBar 90)
  • converted everything in overlays/ to 4 spaces/tab ;)
  • removed all using namespace Ogre;
  • added background_ Panel to OrxonoxOverlay, since most of the derived classes can use that
  • should work now, but I'll have to test on a tardis box first
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud/src/orxonox/overlays/OverlayGroup.cc

    r1614 r1615  
    3030#include "OverlayGroup.h"
    3131
    32 #include <assert.h>
    3332#include "core/Debug.h"
    3433#include "core/ConsoleCommand.h"
     
    3837namespace orxonox
    3938{
    40   CreateFactory(OverlayGroup);
     39    CreateFactory(OverlayGroup);
    4140
    42   SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
    43   SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User);
     41    SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
     42    SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User);
     43    SetConsoleCommand(OverlayGroup, scrollGroup, false).setAccessLevel(AccessLevel::User);
    4444
    45   using namespace Ogre;
     45    OverlayGroup::OverlayGroup()
     46        : scale_(1.0, 1.0)
     47    {
     48        RegisterObject(OverlayGroup);
     49    }
    4650
    47   OverlayGroup::OverlayGroup()
    48     : scale_(1.0, 1.0)
    49   {
    50     RegisterObject(OverlayGroup);
    51   }
     51    OverlayGroup::~OverlayGroup()
     52    {
     53    }
    5254
    53   OverlayGroup::~OverlayGroup()
    54   {
    55   }
     55    void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
     56    {
     57        BaseObject::XMLPort(xmlElement, mode);
    5658
    57   void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    58   {
    59     BaseObject::XMLPort(xmlElement, mode);
     59        XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode);
     60        XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode);
     61        XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);
     62    }
    6063
    61     XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode);
    62     XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);
    63   }
     64    void OverlayGroup::setScale(const Vector2& scale)
     65    {
     66        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     67            (*it).second->scale(scale / this->scale_);
     68        this->scale_ = scale;
     69    }
    6470
    65   void OverlayGroup::scale(const Vector2& scale)
    66   {
    67     for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    68       (*it).second->scale(scale);
    69     this->scale_ = scale;
    70   }
     71    void OverlayGroup::setScroll(const Vector2& scroll)
     72    {
     73        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     74            (*it).second->scroll(scroll - this->scroll_);
     75        this->scroll_ = scroll;
     76    }
    7177
    72   void OverlayGroup::addElement(OrxonoxOverlay* element)
    73   {
    74     if (hudElements_.find(element->getName()) != hudElements_.end())
     78    void OverlayGroup::addElement(OrxonoxOverlay* element)
    7579    {
    76       COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
     80        if (hudElements_.find(element->getName()) != hudElements_.end())
     81        {
     82            COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
     83        }
     84        else
     85            hudElements_[element->getName()] = element;
    7786    }
    78     else
    79       hudElements_[element->getName()] = element;
    80   }
    8187
    82   OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
    83   {
    84     if (index < this->hudElements_.size())
     88    OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
    8589    {
    86       std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
    87       for (unsigned int i = 0; i != index; ++it, ++i)
    88         ;
    89       return (*it).second;
     90        if (index < this->hudElements_.size())
     91        {
     92            std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
     93            for (unsigned int i = 0; i != index; ++it, ++i)
     94                ;
     95            return (*it).second;
     96        }
     97        else
     98            return 0;
    9099    }
    91     else
    92       return 0;
    93   }
    94100
    95101
    96   /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
    97   {
    98     for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
     102    /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
    99103    {
    100         if ((*it)->getName() == name)
    101             (*it)->setVisibility(!((*it)->isVisible()));
     104        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
     105        {
     106            if ((*it)->getName() == name)
     107                (*it)->setVisibility(!((*it)->isVisible()));
     108        }
    102109    }
    103   }
    104110
    105   /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
    106   {
    107     for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
     111    /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
    108112    {
    109         if ((*it)->getName() == name)
    110             (*it)->scale(Vector2(scale, scale));
     113        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
     114        {
     115            if ((*it)->getName() == name)
     116                (*it)->scale(Vector2(scale, scale));
     117        }
    111118    }
    112   }
     119
     120    /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll)
     121    {
     122        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
     123        {
     124            if ((*it)->getName() == name)
     125                (*it)->scroll(scroll);
     126        }
     127    }
    113128}
Note: See TracChangeset for help on using the changeset viewer.