Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/overlay/src/orxonox/overlays/stats/CreateLines.cc @ 2386

Last change on this file since 2386 was 2386, checked in by bhildebr, 15 years ago

CreateLines and Scoreboard are now running without segfaults

File size: 2.9 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 *      Benjamin Hildebrandt
24 *
25 */
26
27#include "OrxonoxStableHeaders.h"
28#include "CreateLines.h"
29
30#include <string>
31#include <OgreOverlay.h>
32#include <OgreOverlayElement.h>
33#include <OgreOverlayManager.h>
34#include <OgreOverlayContainer.h>
35
36#include "util/Convert.h"
37#include "util/Debug.h"
38#include "core/CoreIncludes.h"
39#include "core/ConfigValueIncludes.h"
40
41namespace orxonox
42{
43    CreateFactory(CreateLines);
44
45    /**
46        @brief Constructor: Creates a line.
47    */
48    CreateLines::CreateLines(BaseObject* creator)
49        : OrxonoxOverlay(creator)
50    {
51        RegisterObject(CreateLines);
52    }
53
54    /**
55        @brief Initializes the lines.
56    */
57    void CreateLines::XMLPort(Element& xmlElement, XMLPort::Mode mode)
58    {
59        SUPER(CreateLines, XMLPort, xmlElement, mode);
60    }
61
62    /**
63        @brief Ensures that the number of OverlayElements is equal to numberOfColumns.
64    */
65    void CreateLines::setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex) {
66
67        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
68
69        unsigned int colIndex = 0;
70
71        while (textColumns_.size() < numberOfColumns) {
72
73            Ogre::TextAreaOverlayElement* tempTextArea = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "StatsLineTextArea" + getName() + convertToString(lineIndex) + convertToString(colIndex)));
74            textColumns_.push_back(tempTextArea);
75            this->background_->addChild(tempTextArea);
76
77            colIndex++;
78
79        }
80
81        while (textColumns_.size() > numberOfColumns) {
82
83            this->background_->_removeChild(textColumns_.back());
84            ovMan->destroyOverlayElement(textColumns_.back());
85            textColumns_.pop_back();
86
87        }
88
89    }
90
91    void CreateLines::alignColumn(int columnIndex, float leftOffset, float topOffset) {
92
93        this->textColumns_[columnIndex]->setPosition(leftOffset, topOffset);
94
95    }
96
97    void CreateLines::setColumnText(int columnIndex, std::string columnText) {
98
99        this->textColumns_[columnIndex]->setCaption(columnText);
100
101    }
102
103}
Note: See TracBrowser for help on using the repository browser.