Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Grid.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_GRID_H
22 #define GF_GRID_H
23 
24 #include "Portability.h"
25 #include "Transformable.h"
26 #include "Vector.h"
27 #include "VertexArray.h"
28 #include "VertexBuffer.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
39  class GF_API SquareGrid : public gf::Transformable {
40  public:
49  SquareGrid(Vector2u gridSize, Vector2f cellSize, const Color4f& color, float lineWidth = 1.0f);
50 
56  void setGridSize(Vector2u gridSize);
57 
63  Vector2u getGridSize() const noexcept {
64  return m_gridSize;
65  }
66 
72  void setCellSize(Vector2f cellSize);
73 
79  Vector2f getCellSize() const noexcept {
80  return m_cellSize;
81  }
82 
88  void setColor(const Color4f& color);
89 
95  const Color4f& getColor() const noexcept {
96  return m_color;
97  }
98 
104  void setLineWidth(float lineWidth) noexcept {
105  m_lineWidth = lineWidth;
106  }
107 
113  float getLineWidth() const noexcept {
114  return m_lineWidth;
115  }
116 
128  RectF getLocalBounds() const;
129 
140  void setAnchor(Anchor anchor);
141 
150  VertexBuffer commitGeometry() const;
151 
152  virtual void draw(RenderTarget& target, const RenderStates& states) override;
153 
154  private:
155  void updateGeometry();
156 
157  private:
158  Vector2u m_gridSize;
159  Vector2f m_cellSize;
160  Color4f m_color;
161  float m_lineWidth;
162  VertexArray m_vertices;
163  };
164 
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
166 }
167 #endif
168 }
169 
170 #endif // GF_GRID_H
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
A set of primitives.
Definition: VertexArray.h:65
Vector2f getCellSize() const noexcept
Get the cell size.
Definition: Grid.h:79
float getLineWidth() const noexcept
Get the width of the grid frame.
Definition: Grid.h:113
void setLineWidth(float lineWidth) noexcept
Set the width of the grid frame.
Definition: Grid.h:104
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
Data in the graphics memory.
Definition: VertexBuffer.h:70
The namespace for gf classes.
Definition: Action.h:35
A square grid.
Definition: Grid.h:39
const Color4f & getColor() const noexcept
Get the color of the grid frame.
Definition: Grid.h:95
Anchor
An anchor of a box.
Definition: Anchor.h:38
Vector2u getGridSize() const noexcept
Get the grid size.
Definition: Grid.h:63