Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud/src/orxonox/overlays/OverlayGroup.cc @ 1615

Last change on this file since 1615 was 1615, checked in by rgrieder, 16 years ago
  • 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
  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "OverlayGroup.h"
31
32#include "core/Debug.h"
33#include "core/ConsoleCommand.h"
34#include "core/CoreIncludes.h"
35#include "OrxonoxOverlay.h"
36
37namespace orxonox
38{
39    CreateFactory(OverlayGroup);
40
41    SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
42    SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User);
43    SetConsoleCommand(OverlayGroup, scrollGroup, false).setAccessLevel(AccessLevel::User);
44
45    OverlayGroup::OverlayGroup()
46        : scale_(1.0, 1.0)
47    {
48        RegisterObject(OverlayGroup);
49    }
50
51    OverlayGroup::~OverlayGroup()
52    {
53    }
54
55    void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
56    {
57        BaseObject::XMLPort(xmlElement, mode);
58
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    }
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    }
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    }
77
78    void OverlayGroup::addElement(OrxonoxOverlay* element)
79    {
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;
86    }
87
88    OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
89    {
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;
99    }
100
101
102    /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
103    {
104        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
105        {
106            if ((*it)->getName() == name)
107                (*it)->setVisibility(!((*it)->isVisible()));
108        }
109    }
110
111    /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
112    {
113        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
114        {
115            if ((*it)->getName() == name)
116                (*it)->scale(Vector2(scale, scale));
117        }
118    }
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    }
128}
Note: See TracBrowser for help on using the repository browser.