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
#include "fsCNativeLine.h"

#include <base/Director.h>
#include <2d/DrawNode.h>

#include <fsCore/fsSColour.h>
#include <fsCore/fsAffineMtx2d.h>


void fsCNativeLine::renderDo()
{
	mImpl->visit(ax::Director::getInstance()->getRenderer(), mRenderMatrix, ax::Node::FLAGS_TRANSFORM_DIRTY);
}

void fsCNativeLine::alphaBlendModeSetDo(fsS32 pAlphaBlendMode)
{
	// 	if (fsCMaterial::eALPHA_ADD == pAlphaBlendMode)
	// 	{
	// 		mImpl->setBlendFunc(ax::BlendFunc::ALPHA_PREMULTIPLIED);
	// 	}
	// 	mImpl->setOpacityModifyRGB(true);
}

void fsCNativeLine::vertsSetDo(std::vector<fsVec2d> const& pVerts)
{
	mRawVerts.clear();
	for (auto vert : pVerts)
	{
		mRawVerts.push_back(ax::Vec2(vert.x, vert.y));<--- Consider using std::transform algorithm instead of a raw loop.
	}
	mImpl->clear();
	mImpl->drawPoly(
		&mRawVerts[0],
		mRawVerts.size(),
		false,
		mColour,
		3.0f);
}

ax::Node* fsCNativeLine::implGet() const
{
	return mImpl;
}

void fsCNativeLine::matrixApplyDo(const fsAffineMtx2d& pRenderMatrix)
{
	mRenderMatrix.m[12] = pRenderMatrix.get(0, 2);
	mRenderMatrix.m[13] = pRenderMatrix.get(1, 2);

	mRenderMatrix.m[0] = pRenderMatrix.get(0, 0);
	mRenderMatrix.m[1] = pRenderMatrix.get(1, 0);
	mRenderMatrix.m[4] = pRenderMatrix.get(0, 1);
	mRenderMatrix.m[5] = pRenderMatrix.get(1, 1);
}

void fsCNativeLine::colourSetDo(const fsSColour4B& pColour)
{
#ifdef AXMOL_V3
	mColour = ax::Color32(pColour.mR / 255.f, pColour.mG / 255.f, pColour.mB / 255.f, pColour.mA / 255.f);
#else
	mColour = ax::Color4F(pColour.mR / 255.f, pColour.mG / 255.f, pColour.mB / 255.f, pColour.mA / 255.f);
#endif

}

fsCNativeLine::fsCNativeLine():
	fsINative(),
	mRawVerts(2)
{
	mImpl = ax::DrawNode::create();
	mImpl->retain();
}

fsCNativeLine::~fsCNativeLine()
{
	if (mImpl->getParent())
	{
		mImpl->removeFromParentAndCleanup(true);
	}
	mImpl->release();
	mImpl = nullptr;
}