Angel 3.2
A 2D Game Prototyping Engine
TextActor.h
Go to the documentation of this file.
1 
2 // Copyright (C) 2008-2013, Shane Liesegang
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of the copyright holder nor the names of any
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
29 
31 #pragma once
32 
33 #include "../Actors/Actor.h"
34 
39 {
40  TXT_Left,
41  TXT_Center,
42  TXT_Right
43 };
44 
46 
54 class TextActor : public Actor
55 {
56 public:
68  TextActor(const String& fontNickname="Console", const String& displayString="", TextAlignment align=TXT_Left, int lineSpacing=5);
69 
73  virtual void Render();
74 
80  const String& GetFont() const;
81 
89  void SetFont(const String& newFont);
90 
96  const String& GetDisplayString() const;
97 
105  void SetDisplayString(const String& newString);
106 
112  const TextAlignment GetAlignment();
113 
119  void SetAlignment(TextAlignment newAlignment);
120 
126  const int GetLineSpacing();
127 
133  void SetLineSpacing(int newSpacing);
134 
143  virtual void SetPosition(float x, float y);
144 
153  virtual void SetPosition(const Vector2& position);
154 
163  virtual void SetRotation(float newRotation);
164 
172  virtual void ReceiveMessage(Message* message);
173 
183  const BoundingBox& GetBoundingBox() const;
184 
191  virtual const String GetClassName() const { return "TextActor"; }
192 
193 private:
194  struct TextNugget
195  {
196  String _string;
197  Vector2 _extents;
198  Vector2 _position;
199  };
200 
201  void CalculatePosition();
202 
203  String _fontNickname;
204  String _rawString;
205  TextAlignment _alignment;
206 
207  std::vector<TextNugget> _displayStrings;
208 
209  int _lineSpacing;
210 
211  Vector2 _screenPosition;
212 
213  BoundingBox _extents;
214 };