1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 |
#include "fsCNativeSprite.h"
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/Math/Matrix4.h>
#include <Magnum/Math/Math.h>
#include <Magnum/Math/RectangularMatrix.h>
#include <fsAppCore/fsIDisplay.h>
#include <fsCore/fsRect.h>
#include "../../../src/fsCBrush.h"
#include "../../../fsISpriteRenderData.h"
#include "../fsCTexture.h"
Magnum::Shaders::FlatGL3D* fsCNativeSprite::mShader = nullptr;
Magnum::Matrix4 fsCNativeSprite::projectionMatrix;
void fsCNativeSprite::renderDo()
{
if(mWidth && mHeight)
{
mShader
->bindTexture(*mTexture)
.setTransformationProjectionMatrix( mRenderMatrix )
.draw(mMesh);
}
}
void fsCNativeSprite::brushSetDo(std::shared_ptr<fsCBrush> pBrush)
{
mBrush = pBrush;
mWidth = pBrush->dimensionsGet().x;
mHeight = pBrush->dimensionsGet().y;
mTexture = (static_cast<fsCTexture*>(pBrush->textureGet().get())->textureGet());
fsVec2d uv0 = {
static_cast<fsF32>(pBrush->offsetGet().x) / static_cast<fsF32>(pBrush->textureGet()->imageWidthGet()),
static_cast<fsF32>(pBrush->textureGet()->imageHeightGet() - pBrush->offsetGet().y- pBrush->dimensionsGet().y) / static_cast<fsF32>(pBrush->textureGet()->imageHeightGet())};
fsVec2d uv1 = {
static_cast<fsF32>(pBrush->offsetGet().x + pBrush->dimensionsGet().x) / static_cast<fsF32>(pBrush->textureGet()->imageWidthGet()),
static_cast<fsF32>(pBrush->textureGet()->imageHeightGet() - pBrush->offsetGet().y) / static_cast<fsF32>(pBrush->textureGet()->imageHeightGet())};
const TriangleVertex data[]{
{{-0.5f * mWidth,-0.5f * mHeight}, {uv0.x, uv0.y}},
{{-0.5f * mWidth,+0.5f * mHeight}, {uv0.x, uv1.y}},
{{+0.5f * mWidth,+0.5f * mHeight}, {uv1.x, uv1.y}},
{{+0.5f * mWidth,-0.5f * mHeight}, {uv1.x, uv0.y}},
{{-0.5f * mWidth,-0.5f * mHeight}, {uv0.x, uv0.y}},
{{+0.5f * mWidth,+0.5f * mHeight}, {uv1.x, uv1.y}},
};
Magnum::GL::Buffer buffer;
buffer.setData(data);
mMesh.setCount(6)
.addVertexBuffer(std::move(buffer), 0,
Magnum::Shaders::FlatGL2D::Position{},
Magnum::Shaders::FlatGL2D::TextureCoordinates{});
}
void fsCNativeSprite::matrixApplyDo(const fsAffineMtx2d& pRenderMatrix)
{
fsF32 m[16] = {0.0};
m[0] = 1.0f;
m[5] = 1.0f;
m[10] = 1.0f;
m[15] = 1.0f;
m[0] = pRenderMatrix.get(0, 0);
m[1] = pRenderMatrix.get(0, 1);
m[4] = pRenderMatrix.get(1, 0);
m[5] = pRenderMatrix.get(1, 1);
m[12] = pRenderMatrix.get(0, 2);
m[13] = -pRenderMatrix.get(1, 2);
m[14] = -0.01;
mRenderMatrix = Magnum::Math::Matrix4x4<fsF32>::from(m);
mRenderMatrix = projectionMatrix * mRenderMatrix;
}
fsBool fsCNativeSprite::hitTest(const fsPoint& pLocalPos, fsBool pRequireHitMap) const<--- The member function 'fsCNativeSprite::hitTest' can be static.
{
return false;
}
fsS32 fsCNativeSprite::widthGet() const
{
return mWidth;
}
fsS32 fsCNativeSprite::heightGet() const
{
return mHeight;
}
std::shared_ptr<fsCBrush> fsCNativeSprite::brushGet() const
{
return mBrush;
}
fsCNativeSprite::fsCNativeSprite():
fsINative(),
mWidth(0),
mHeight(0),
mBrush(nullptr),
mTexture(nullptr)
{
mScreenWidth = fsIDisplay::instanceGet()->visibleCanvasWidthGet();<--- Variable 'mScreenWidth' is assigned in constructor body. Consider performing initialization in initialization list. [+]When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'mScreenWidth' a value by passing the value to the constructor in the initialization list.
mScreenHeight = fsIDisplay::instanceGet()->visibleCanvasHeightGet();
}
fsCNativeSprite::~fsCNativeSprite()
{
}
|