Orxonox  0.0.5 Codename: Arcturus
OrxonoxOverlay.h
Go to the documentation of this file.
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 
34 #ifndef _OrxonoxOverlay_H__
35 #define _OrxonoxOverlay_H__
36 
37 #include "OrxonoxPrereqs.h"
38 
39 #include <string>
40 
41 #include "util/Math.h"
42 #include "util/OgreForwardRefs.h"
43 #include "core/BaseObject.h"
45 #include "core/class/Super.h"
46 
47 namespace orxonox
48 {
73  {
74  public:
81  enum class RotationState
82  {
83  Horizontal,
84  Vertical,
85  Inbetween
86  };
87 
88  public:
89  OrxonoxOverlay(Context* context);
90  virtual ~OrxonoxOverlay();
91 
92  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
93 
94  virtual void changedName() override;
95 
97  void show() { this->setVisible(true); }
99  void hide() { this->setVisible(false); }
100 
104  void setAspectCorrection(bool val) { this->bCorrectAspect_ = val; this->sizeCorrectionChanged(); }
106  bool getAspectCorrection() const { return this->bCorrectAspect_; }
107 
109  void setPosition(Vector2 pos) { this->position_ = pos; this->positionChanged(); }
110 
112  const Vector2& getPosition() const { return this->position_; }
113 
115  void scroll(const Vector2& offset) { this->position_ += offset; this->positionChanged(); }
116 
121  void setPickPoint(const Vector2& position){ this->pickPoint_ = position; this->positionChanged(); }
122 
124  const Vector2& getPickPoint() const { return this->pickPoint_; }
125 
127  void setRotation(const Degree& angle) { this->angle_ = angle; this->angleChanged(); }
128 
130  const Degree& getRotation() const { return this->angle_; }
131 
133  void rotate(const Degree& angle) { this->angle_ += angle; this->angleChanged(); }
134 
136  void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); }
137 
139  const Vector2& getSize() const { return this->size_; }
140 
142  Vector2 getActualSize() const { return this->size_ * this->sizeCorrection_; }
143 
145  const Vector2& getSizeCorrection() const { return this->sizeCorrection_; }
146 
148  void scale(const Vector2& scale) { this->size_ *= scale; this->sizeChanged(); }
149 
151  static void scaleOverlay(const std::string& name, float scale);
153  static void scrollOverlay(const std::string& name, const Vector2& scroll);
154  static void toggleVisibility(const std::string& name);
155  static void showOverlay(const std::string& name);
157  static void rotateOverlay(const std::string& name, const Degree& angle);
158 
159  void setBackgroundMaterial(const std::string& material);
160  const std::string& getBackgroundMaterial() const;
161 
162  void setBackgroundTexture(const std::string& texture);
163  const std::string& getBackgroundTexture() const;
164 
165  void setBackgroundAlpha(float alpha);
166 
167  void setBackgroundColour(ColourValue colour);
168 
169  virtual void changedVisibility() override;
170 
171  inline void setOwner(BaseObject* owner)
172  {
173  if (this->owner_ != owner)
174  {
175  this->owner_ = owner;
176  this->changedOwner();
177  }
178  }
179  inline BaseObject* getOwner() const
180  { return this->owner_; }
181  virtual void changedOwner() {}
182 
183  void setOverlayGroup(OverlayGroup* group);
185  { return this->group_; }
186  virtual void changedOverlayGroup()
187  { this->changedVisibility(); }
188  void setZOrder(unsigned short order);
189 
190  protected:
191  virtual void angleChanged();
192  virtual void sizeCorrectionChanged();
193  virtual void sizeChanged();
194  virtual void positionChanged();
195 
196  Ogre::Overlay* overlay_;
197  Ogre::PanelOverlayElement* background_;
198 
201  Vector2 size_;
202  Vector2 sizeCorrection_;
203  Vector2 position_;
204  Vector2 pickPoint_;
205  Degree angle_;
207 
208  private:
209  virtual void windowResized(unsigned int newWidth, unsigned int newHeight) override;
210 
211  static unsigned int hudOverlayCounter_s;
212 
214  static std::map<std::string, OrxonoxOverlay*> overlays_s;
217  Ogre::Pass* backgroundAlphaPass_;
218  };
219 
220  SUPER_FUNCTION(6, OrxonoxOverlay, changedOwner, false);
221  SUPER_FUNCTION(7, OrxonoxOverlay, changedOverlayGroup, false);
222 }
223 
224 #endif /* _OrxonoxOverlay_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
BaseObject * getOwner() const
Definition: OrxonoxOverlay.h:179
Vector2 size_
Internal size of the overlay.
Definition: OrxonoxOverlay.h:201
void setAspectCorrection(bool val)
Sets whether the aspect of the overlay is corrected.
Definition: OrxonoxOverlay.h:104
Degree angle_
Rotation angle of the overlay.
Definition: OrxonoxOverlay.h:205
Ogre::Pass * backgroundAlphaPass_
Definition: OrxonoxOverlay.h:217
void hide()
Hides the overlay with an detour to BaseObject::visibility_.
Definition: OrxonoxOverlay.h:99
::std::string string
Definition: gtest-port.h:756
const Vector2 & getSizeCorrection() const
Gets the current size correction (default: 1.0, 1.0)
Definition: OrxonoxOverlay.h:145
Interface for receiving window events like resize, moved and focusChanged.
Definition: WindowEventListener.h:43
Ogre::Overlay * overlay_
The overlay the entire class is about.
Definition: OrxonoxOverlay.h:196
void setSize(const Vector2 &size)
Sets the size of this overlay.
Definition: OrxonoxOverlay.h:136
virtual void changedOverlayGroup()
Definition: OrxonoxOverlay.h:186
Vector2 position_
Position of the pickPoint on the screen.
Definition: OrxonoxOverlay.h:203
Ogre::ColourValue colour(const btVector3 &color, btScalar alpha)
Definition: OgreBulletUtils.h:41
const Vector2 & getSize() const
Gets the current size that was set (uncorrected)
Definition: OrxonoxOverlay.h:139
bool getAspectCorrection() const
Returns whether the window aspect is corrected.
Definition: OrxonoxOverlay.h:106
SUPER_FUNCTION(0, BaseObject, XMLPort, false)
const Vector2 & getPickPoint() const
Gets the pick point of this overlay.
Definition: OrxonoxOverlay.h:124
static unsigned int hudOverlayCounter_s
Static counter for hud elements.
Definition: OrxonoxOverlay.h:211
xmlelement
Definition: Super.h:519
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
Ogre::PanelOverlayElement * background_
Background image (blank per default).
Definition: OrxonoxOverlay.h:197
const Vector2 & getPosition() const
Returns the current position on the screen.
Definition: OrxonoxOverlay.h:112
static std::map< std::string, OrxonoxOverlay * > overlays_s
Contains all the overlays in a map for quick access via console commands.
Definition: OrxonoxOverlay.h:214
RotationState
Describes the rotational state of a an overlay.
Definition: OrxonoxOverlay.h:81
void rotate(const Degree &angle)
Rotates the overlay by angle degrees.
Definition: OrxonoxOverlay.h:133
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
bool bCorrectAspect_
Whether or not to correct the size.
Definition: OrxonoxOverlay.h:200
float windowAspectRatio_
Screen.width / screen.height.
Definition: OrxonoxOverlay.h:199
Vector2 pickPoint_
Point on the overlay to pick when translating.
Definition: OrxonoxOverlay.h:204
Mode
Definition: CorePrereqs.h:102
Shared library macros, enums, constants and forward declarations for the orxonox library ...
OverlayGroup * getOverlayGroup() const
Definition: OrxonoxOverlay.h:184
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
void show()
Shows the overlay with an detour to BaseObject::visibility_.
Definition: OrxonoxOverlay.h:97
Base class to display content directly onto the screen.
Definition: OrxonoxOverlay.h:72
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
OverlayGroup does almost exactly what it says: It groups OrxonoxOverlays together.
Definition: OverlayGroup.h:53
void scroll(const Vector2 &offset)
Scrolls the overlay.
Definition: OrxonoxOverlay.h:115
RotationState rotState_
horizontal, vertical or inbetween
Definition: OrxonoxOverlay.h:206
void setPickPoint(const Vector2 &position)
Sets the point in the overlay where to pick it when translating.
Definition: OrxonoxOverlay.h:121
const Degree & getRotation() const
Gets the rotation angle applied to this overlay in degrees.
Definition: OrxonoxOverlay.h:130
virtual void changedOwner()
Definition: OrxonoxOverlay.h:181
void setPosition(Vector2 pos)
Sets the position of this overlay on the screen.
Definition: OrxonoxOverlay.h:109
void setRotation(const Degree &angle)
Sets the rotation angle applied to this overlay in degrees.
Definition: OrxonoxOverlay.h:127
BaseObject * owner_
Definition: OrxonoxOverlay.h:215
Vector2 getActualSize() const
Gets the actual size of the overlay on the screen (corrected)
Definition: OrxonoxOverlay.h:142
Definition of all super-function related macros, used to call functions of the base class...
OverlayGroup * group_
Definition: OrxonoxOverlay.h:216
void scale(const Vector2 &scale)
Scales the overlay by scale.
Definition: OrxonoxOverlay.h:148
Vector2 sizeCorrection_
Value to correct the size because of the window aspect.
Definition: OrxonoxOverlay.h:202
void setOwner(BaseObject *owner)
Definition: OrxonoxOverlay.h:171