Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1618 was 1616, checked in by rgrieder, 16 years ago
  • precompiled header files have disadvantages too…
  • 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 "core/XMLPort.h"
36#include "OrxonoxOverlay.h"
37
38namespace orxonox
39{
40    CreateFactory(OverlayGroup);
41
42    SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
43    SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User);
44    SetConsoleCommand(OverlayGroup, scrollGroup, false).setAccessLevel(AccessLevel::User);
45
46    OverlayGroup::OverlayGroup()
47        : scale_(1.0, 1.0)
48    {
49        RegisterObject(OverlayGroup);
50    }
51
52    OverlayGroup::~OverlayGroup()
53    {
54    }
55
56    void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
57    {
58        BaseObject::XMLPort(xmlElement, mode);
59
60        XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode);
61        XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode);
62        XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);
63    }
64
65    void OverlayGroup::setScale(const Vector2& scale)
66    {
67        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
68            (*it).second->scale(scale / this->scale_);
69        this->scale_ = scale;
70    }
71
72    void OverlayGroup::setScroll(const Vector2& scroll)
73    {
74        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
75            (*it).second->scroll(scroll - this->scroll_);
76        this->scroll_ = scroll;
77    }
78
79    void OverlayGroup::addElement(OrxonoxOverlay* element)
80    {
81        if (hudElements_.find(element->getName()) != hudElements_.end())
82        {
83            COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
84        }
85        else
86            hudElements_[element->getName()] = element;
87    }
88
89    OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
90    {
91        if (index < this->hudElements_.size())
92        {
93            std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
94            for (unsigned int i = 0; i != index; ++it, ++i)
95                ;
96            return (*it).second;
97        }
98        else
99            return 0;
100    }
101
102
103    /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
104    {
105        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
106        {
107            if ((*it)->getName() == name)
108                (*it)->setVisibility(!((*it)->isVisible()));
109        }
110    }
111
112    /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
113    {
114        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
115        {
116            if ((*it)->getName() == name)
117                (*it)->scale(Vector2(scale, scale));
118        }
119    }
120
121    /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll)
122    {
123        for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
124        {
125            if ((*it)->getName() == name)
126                (*it)->scroll(scroll);
127        }
128    }
129}
Note: See TracBrowser for help on using the repository browser.