Spinning Topp Logo BlackTopp Studios
inc
linelist.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uilinelist_cpp
41 #define _uilinelist_cpp
42 
43 #include "UI/linelist.h"
44 #include "UI/uienumerations.h"
45 #include "UI/uimanager.h"
46 #include "UI/screen.h"
47 #include "UI/simplerenderer.h"
48 
49 namespace Mezzanine
50 {
51  namespace UI
52  {
53  ///////////////////////////////////////////////////////////////////////////////
54  // LineListRenderer Methods
55 
56  ///////////////////////////////////////////////////////////////////////////////
57  /// @brief This is a renderer class specifically designed to draw lines.
58  /// @details
59  ///////////////////////////////////////
61  {
62  protected:
63  /// @brief a pointer to the LineList this rendered is rendering for.
65 
66  /// @copydoc SimpleRenderer::RedrawImpl(Boole)
67  virtual void RedrawImpl(Boole Force)
68  {
69  if( !this->Parent->IsVisible() ) {
70  this->Dirty = false;
71  return;
72  }
73 
74  const LineList::PointVector& Positions = this->Parent->GetPoints();
75  const ColourValue& Colour = this->Parent->GetLineColour();
76  const Real& Thickness = this->Parent->GetLineThickness();
77  Boole IsClosed = this->Parent->IsClosed();
78 
79  if(Positions.size() < 2)
80  return;
81 
82  VertexData Temp;
83  Real HalfThickness = Thickness * 0.5;
84  Vector2 PerpNorm, LastLeft, LastRight, ThisLeft, ThisRight, UV = this->Parent->GetScreen()->GetWhitePixel(PriAtlas);
85  size_t Index = 1;
86  while( Index < Positions.size() )
87  {
88  PerpNorm = (Positions[Index] - Positions[Index - 1]).Perpendicular().Normalize();
89  LastLeft = Positions[Index -1 ] - PerpNorm * HalfThickness;
90  LastRight = Positions[Index -1 ] + PerpNorm * HalfThickness;
91  ThisLeft = Positions[Index] - PerpNorm * HalfThickness;
92  ThisRight = Positions[Index] + PerpNorm * HalfThickness;
93 
94  // Triangle A
95  this->PushVertex(LastRight.X,LastRight.Y,UV,Colour,PriAtlas); // Left/Bottom
96  this->PushVertex(ThisLeft.X,ThisLeft.Y,UV,Colour,PriAtlas); // Right/Top
97  this->PushVertex(LastLeft.X,LastLeft.Y,UV,Colour,PriAtlas); // Left/Top
98  // Triangle B
99  this->PushVertex(LastRight.X,LastRight.Y,UV,Colour,PriAtlas); // Left/Bottom
100  this->PushVertex(ThisRight.X,ThisRight.Y,UV,Colour,PriAtlas); // Right/Bottom
101  this->PushVertex(ThisLeft.X,ThisLeft.Y,UV,Colour,PriAtlas); // Right/Top
102 
103  ++Index;
104  }
105 
106  if(IsClosed) {
107  Index = Positions.size() - 1;
108  PerpNorm = (Positions[0] - Positions[Index]).Perpendicular().Normalize();
109  LastLeft = Positions[Index] - PerpNorm * HalfThickness;
110  LastRight = Positions[Index] + PerpNorm * HalfThickness;
111  ThisLeft = Positions[0] - PerpNorm * HalfThickness;
112  ThisRight = Positions[0] + PerpNorm * HalfThickness;
113 
114  // Triangle A
115  this->PushVertex(LastRight.X,LastRight.Y,UV,Colour,PriAtlas); // Left/Bottom
116  this->PushVertex(ThisLeft.X,ThisLeft.Y,UV,Colour,PriAtlas); // Right/Top
117  this->PushVertex(LastLeft.X,LastLeft.Y,UV,Colour,PriAtlas); // Left/Top
118  // Triangle B
119  this->PushVertex(LastRight.X,LastRight.Y,UV,Colour,PriAtlas); // Left/Bottom
120  this->PushVertex(ThisRight.X,ThisRight.Y,UV,Colour,PriAtlas); // Right/Bottom
121  this->PushVertex(ThisLeft.X,ThisLeft.Y,UV,Colour,PriAtlas); // Right/Top
122  }
123  }
124  public:
125  /// @brief Class constructor.
126  /// @param LL The parent LineList this renderer is rendering.
128  Parent(LL)
129  { }
130  /// @brief Class destructor.
132  { }
133 
134  /// @copydoc UI::SimpleRenderer::_MarkDirty()
135  virtual void _MarkDirty()
136  {
137  if(this->Dirty)
138  return;
139  this->Parent->_MarkDirty();
140  this->Dirty = true;
141  }
142  };//LineListRenderer
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // LineList Methods
146 
147  LineList::LineList(const String& RendName, Screen* PScreen) :
148  Renderable(RendName,PScreen),
149  Renderer(NULL),
150  Thickness(1.0),
151  Closed(false)
152  {
153  this->Colour = ColourValue::Black();
154  this->Renderer = new LineListRenderer(this);
155  }
156 
158  {
159  delete this->Renderer;
160  }
161 
162  LineList& LineList::Begin(const Whole& LineThickness, const ColourValue& LineColour)
163  {
164  this->Positions.clear();
165  this->Thickness = LineThickness;
166  this->Colour = LineColour;
167  //_MarkDirty();
168  return *this;
169  }
170 
171  LineList& LineList::AddPoint(const Real& X, const Real& Y)
172  {
173  this->AddPoint(Vector2(X,Y));
174  return *this;
175  }
176 
178  {
179  this->Positions.push_back(Position * this->GetScreen()->GetViewportDimensions());
180  return *this;
181  }
182 
184  {
185  this->AddPoint(Vector2(X,Y));
186  return *this;
187  }
188 
190  {
191  this->Positions.push_back(Position);
192  return *this;
193  }
194 
195  void LineList::End(Boole Closed)
196  {
197  this->Closed = Closed;
198  //_MarkDirty();
199  }
200 
201  ///////////////////////////////////////////////////////////////////////////////
202  // Utility Methods
203 
205  {
206  return Renderable::RT_LineList;
207  }
208 
210  {
211  return this->Positions;
212  }
213 
215  {
216  return this->Closed;
217  }
218 
220  {
221  return this->Colour;
222  }
223 
225  {
226  return this->Thickness;
227  }
228 
229  ///////////////////////////////////////////////////////////////////////////////
230  // Visibility Methods
231 
233  {
234  if( this->Visible == CanSee )
235  return;
236  this->Visible = CanSee;
237  //_MarkDirty();
238  }
239 
241  {
242  return this->Visible;
243  }
244 
246  {
247  return (this->Visible && ParentScreen->IsVisible());
248  }
249 
251  {
252  this->SetVisible(true);
253  }
254 
256  {
257  this->SetVisible(false);
258  }
259 
260  ///////////////////////////////////////////////////////////////////////////////
261  // Utility Methods
262 
264  {
265  /*Vector2 OldMid = ViewportUpdateTool::GetOldSize() * 0.5;
266  Vector2 NewMid = ViewportUpdateTool::GetNewSize() * 0.5;
267 
268  for( Whole Index = 0 ; Index < Positions.size() ; Index++ )
269  {
270  Positions[Index] = (Positions[Index] - OldMid) + NewMid;
271  }// */
272  //_MarkDirty();
273  }
274 
275  ///////////////////////////////////////////////////////////////////////////////
276  // Internal Methods
277 
279  {
280  this->Dirty = true;
281  }
282 
284  {
285  if( this->Renderer->_IsDirty() )
286  this->Renderer->_Redraw(false);
287  this->Renderer->_AppendVertices(RenderData.Vertices);
288  }
289  }//UI
290 }//Mezzanine
291 
292 #endif
ColourValue Colour
The colour of the line.
Definition: linelist.h:70
A simple class providing basic methods to generate vertices with.
virtual Boole GetVisible() const
Gets the visibility setting of this renderable.
Definition: linelist.cpp:240
Basic class for all structures that get inserted into the rendering hierarchy.
Definition: renderable.h:58
virtual void SetVisible(Boole CanSee)
Sets the visibility of this renderable.
Definition: linelist.cpp:232
LineList & Begin(const Whole &LineThickness, const ColourValue &LineColour)
Starts a new line list.
Definition: linelist.cpp:162
Boole _IsDirty()
Gets whether or not this renderer is dirty.
std::vector< VertexData > Vertices
Container storing all of the vertices to be rendered.
Definition: screen.h:119
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual void Hide()
Forces this renderable to hide.
Definition: linelist.cpp:255
virtual Boole IsVisible() const
Gets whether or not this renderable is being drawn.
Definition: screen.cpp:370
void _AppendVertices(std::vector< VertexData > &Vertices)
Appends the vertices of this renderable to another vector.
virtual void _MarkDirty()
Marks this renderable as dirty, and informs other renderables if needed.
Definition: linelist.cpp:278
LineList & AddPoint(const Real &X, const Real &Y)
Adds a new point/line to the list via 2 reals.
Definition: linelist.cpp:171
const ColourValue & GetLineColour() const
Gets the colour of this linelist.
Definition: linelist.cpp:219
Boole IsClosed() const
Gets whether or not this linelist is enclosed.
Definition: linelist.cpp:214
virtual void Show()
Forces this renderable to be shown.
Definition: linelist.cpp:250
Boole Visible
Stores whether this Renderable is to be rendered (also dependent on parent visibility).
Definition: renderable.h:75
virtual Boole IsVisible() const
Gets whether or not this renderable is being drawn.
Definition: linelist.cpp:245
Screen * GetScreen() const
Gets the parent screen of this renderable.
Definition: renderable.cpp:80
static ColourValue Black()
Creates a ColourValue representing the colour Black.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
virtual void UpdateDimensions()
Updates the dimensions of this QuadRenderable based on the transform of it's parent.
Definition: linelist.cpp:263
virtual ~LineList()
Class destructor.
Definition: linelist.cpp:157
This is a renderer class specifically designed to draw lines.
Definition: linelist.cpp:60
LineList(const String &RendName, Screen *PScreen)
Class constructor.
Definition: linelist.cpp:147
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
LineList * Parent
a pointer to the LineList this rendered is rendering for.
Definition: linelist.cpp:64
void End(Boole Closed=false)
Finalizes the list and prepares it for rendering.
Definition: linelist.cpp:195
Vector2 GetWhitePixel(const String &Atlas) const
Gets the position of the white pixel from an Atlas.
Definition: screen.cpp:883
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
RenderableType GetRenderableType() const
Gets the type of renderable this is.
Definition: linelist.cpp:204
Real Thickness
The pixel thickness of the each line segment in this linelist.
Definition: linelist.h:79
const Real & GetLineThickness() const
Gets the thickness of the line generated by this linelist.
Definition: linelist.cpp:224
Real X
Coordinate on the X vector.
Definition: vector2.h:67
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
virtual ~LineListRenderer()
Class destructor.
Definition: linelist.cpp:131
std::vector< Vector2 > PointVector
Basic container type for the storage of all the points in 2D space that create the line to be rendere...
Definition: linelist.h:65
const PointVector & GetPoints() const
Gets the vector of points stored by this linelist.
Definition: linelist.cpp:209
PointVector Positions
The points in 2D space that create this line.
Definition: linelist.h:73
Basic class describing a vertex in the UI to be rendered.
Definition: vertex.h:65
virtual void _AppendRenderData(ScreenRenderData &RenderData)
Appends the vertices of this renderable to another vector.
Definition: linelist.cpp:283
LineList & AddActualPoint(const Real &X, const Real &Y)
Adds a new point/line to the list via 2 reals.
Definition: linelist.cpp:183
virtual void _MarkDirty()
Marks this renderable as well as all parent objects as dirty.
Definition: linelist.cpp:135
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
LineListRenderer * Renderer
The internal renderer responsible for generating this lines vertices.
Definition: linelist.h:76
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
This class stores all vertices pertaining to a layer sorted by their priority for rendering...
Definition: screen.h:115
Boole Closed
A bool indicating whether or not an additional segment should be generated between the first and last...
Definition: linelist.h:82
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Vector2 & Normalize()
Normalizes this Vector2.
Definition: vector2.cpp:269
Boole Dirty
Stores whether this Renderables vertices need to be regenerated.
Definition: renderable.h:78
void _Redraw(Boole Force)
Regenerates the verticies in this renderable.
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
RenderableType
A small enum to describe the type of renderable this is.
Definition: renderable.h:62
virtual void RedrawImpl(Boole Force)
Provides the class specific implementation for regenerating vertices for this renderable.
Definition: linelist.cpp:67
LineListRenderer(LineList *LL)
Class constructor.
Definition: linelist.cpp:127
This is an object comprised of a series of lines.
Definition: linelist.h:61
Screen * ParentScreen
A pointer to the Screen that created this Renderable.
Definition: renderable.h:72