Gamedev Framework (gf)
0.16.0
A C++14 framework for 2D games
include
gf
NinePatch.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_NINE_PATCH_H
22
#define GF_NINE_PATCH_H
23
24
#include "Portability.h"
25
#include "Transformable.h"
26
#include "Vertex.h"
27
#include "VertexBuffer.h"
28
29
namespace
gf
{
30
#ifndef DOXYGEN_SHOULD_SKIP_THIS
31
inline
namespace
v1 {
32
#endif
33
34
class
Texture
;
35
46
class
GF_API
NinePatch
:
public
Transformable
{
47
public
:
53
NinePatch
();
54
62
NinePatch
(
const
Texture
& texture);
63
72
NinePatch
(
const
Texture
& texture,
const
RectF
& textureRect);
73
92
void
setTexture(
const
Texture
& texture,
bool
resetRect =
false
);
93
104
const
Texture
&
getTexture
()
const
{
105
return
*m_texture;
106
}
107
115
bool
hasTexture
()
const
{
116
return
m_texture !=
nullptr
;
117
}
118
126
void
unsetTexture();
127
143
void
setTextureRect(
const
RectF
& rect);
144
152
const
RectF
&
getTextureRect
()
const
{
153
return
m_textureRect;
154
}
155
169
void
setColor(
const
Color4f
& color);
170
178
const
Color4f
& getColor()
const
;
179
190
void
setLimits(
float
top,
float
bottom,
float
left,
float
right);
191
200
void
setVerticalLimits(
float
top,
float
bottom);
201
210
void
setHorizontalLimits(
float
left,
float
right);
211
217
void
setSize(
Vector2f
size);
218
224
Vector2f
getSize
()
const
{
225
return
m_size;
226
}
227
239
RectF
getLocalBounds()
const
;
240
251
void
setAnchor(
Anchor
anchor);
252
261
VertexBuffer
commitGeometry()
const
;
262
263
virtual
void
draw(
RenderTarget
& target,
const
RenderStates
& states)
override
;
264
265
private
:
266
void
updatePositions();
267
void
updateTexCoords();
268
269
private
:
270
const
Texture
*m_texture;
271
RectF
m_textureRect;
272
273
float
m_top;
274
float
m_bottom;
275
float
m_left;
276
float
m_right;
277
278
Vector2f
m_size;
279
280
Vertex
m_vertices[16];
281
};
282
283
284
#ifndef DOXYGEN_SHOULD_SKIP_THIS
285
}
286
#endif
287
}
288
289
#endif // GF_NINE_PATCH_H
gf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition:
Transformable.h:95
gf::NinePatch::getTextureRect
const RectF & getTextureRect() const
Get the sub-rectangle of the texture displayed by the nine-patch.
Definition:
NinePatch.h:152
gf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition:
RenderTarget.h:90
gf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition:
RenderStates.h:82
gf::NinePatch
A nine-patch.
Definition:
NinePatch.h:46
gf::Vertex
A point associated with a color and a texture coordinate.
Definition:
Vertex.h:75
gf::NinePatch::getTexture
const Texture & getTexture() const
Get the source texture of the nine-patch.
Definition:
NinePatch.h:104
gf::VertexBuffer
Data in the graphics memory.
Definition:
VertexBuffer.h:77
gf::Texture
A texture for colored images.
Definition:
Texture.h:309
gf::GraphicsTag::Texture
gf::Rect< float >
gf
The namespace for gf classes.
Definition:
Action.h:35
gf::NinePatch::getSize
Vector2f getSize() const
Get the size of the stretched area.
Definition:
NinePatch.h:224
gf::Vector< T, 4 >
A 4D vector.
Definition:
Vector.h:852
gf::NinePatch::hasTexture
bool hasTexture() const
Check if a texture is set.
Definition:
NinePatch.h:115
gf::Anchor
Anchor
An anchor of a box.
Definition:
Anchor.h:38
gf::Vector< float, 2 >
Generated by
1.8.13