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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "fsITransformationComponent.h"

#include <fsCore/src/fsCVariableTable.h>

#include "../gui/fsIGuiComponent.h"

#include "fsCF32Transformation.h"
#include "fsCFadeTransformation.h"

const fsCUniqueId fsITransformationComponent::mTypeId("fsCTransformationComponent");
const fsStr fsITransformationComponent::mGraphKey("transGraph");

fsBool fsITransformationComponent::reverseGet() const
{
	return mReverse;
}

fsS32 fsITransformationComponent::elapsedTimeGet() const
{
	if (completeGet())
	{
		return mReverse ? 0 : mTransformation->periodGet();
	}
	return mElapsedTime;
}

void fsITransformationComponent::reverseSet(fsBool pState)
{
	mReverse = pState;
}

void fsITransformationComponent::resetDo()
{
	mElapsedTime = mReverse ? mTransformation->periodGet() : 0;
}

void fsITransformationComponent::simpleTransformSet(fsSColour pStart, fsSColour pEnd, fsS32 pDuration, std::function<void()> pCompletionAction)
{
	delete mTransformation;
	mTransformationTarget = parentGet();
	mTransformation = new fsCFadeTransformation();
	mTransformation->simpleTransformSet(pStart, pEnd, pDuration);
	mElapsedTime = 0;
	mOnCompletionAction = pCompletionAction;
}

void fsITransformationComponent::simpleTransformSet(fsF32 pStart, fsF32 pEnd, fsS32 pDuration, std::function<void()> pCompletionAction)
{
	delete mTransformation;
	mTransformationTarget = parentGet();
	mTransformation = new fsCF32Transformation();
	mTransformation->simpleTransformSet(pStart, pEnd, pDuration);
	mElapsedTime = 0;
	mOnCompletionAction = pCompletionAction;
}

fsBool fsITransformationComponent::childTransformationIncompleteGet() const
{
	if (fsCEntity* const childTransformEnt = parentGet()->firstChildEntityWithComponentsOfFamilyType<
		fsITransformationComponent>())
	{
		if (childTransformEnt != parentGet())
		{
			return !childTransformEnt->firstComponentOfFamilyType<fsITransformationComponent>()->completeGet();
		}
	}
	return false;
}

fsBool fsITransformationComponent::completeGet() const
{
	return !mTransformation
		|| (!mReverse && mElapsedTime > mTransformation->periodGet())
		|| (mReverse && mElapsedTime < 0);
}

void fsITransformationComponent::updateDo(fsS32 pDeltaMs)
{
	if (childTransformationIncompleteGet() || completeGet())
	{
		if (mOnCompletionAction)
		{
			mOnCompletionAction();
			mOnCompletionAction = nullptr;
		}
		return;
	}

	mReverse ? mElapsedTime -= pDeltaMs : mElapsedTime += pDeltaMs;
	updateTransform();
}

fsCEntity* fsITransformationComponent::transformationParentGet()
{
	fsINode* parentGui = parentGet();<--- Variable 'parentGui' can be declared as pointer to const
	while (entityHasTransformationComponentGet(parentGui->parentGet()))
	{
		parentGui = parentGui->parentGet();
	}

	return dynamic_cast<fsCEntity*>(parentGui->parentGet());
}

fsBool fsITransformationComponent::entityHasTransformationComponentGet(const fsINode* const pNode)
{
	if (const auto* const entPtr = dynamic_cast<const fsCEntity* const>(pNode))
	{
		return nullptr != entPtr->firstComponentOfFamilyType<fsITransformationComponent>();
	}
	return false;
}

void fsITransformationComponent::transformationCreate(const fsCVariableTable& pVars)
{
	transformationCreateDo(pVars);
}

void fsITransformationComponent::transformationCreateDo(const fsCVariableTable& pVars)
{
	fsStr graphVals = pVars.strGet(mGraphKey);
	mTransformation = new fsCF32Transformation(graphVals);
}

void fsITransformationComponent::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
	fsIComponent::initialiseFromVariableTableDo(pVars);

	transformationCreate(pVars);

	mTransformationTarget = transformationParentGet();
}

fsITransformationComponent::fsITransformationComponent(fsCEntity* const pParent) :
	fsIComponent(pParent),
	mTransformationTarget(nullptr),
	mTransformation(nullptr),
	mElapsedTime(0),
	mReverse(false)
{
}

fsITransformationComponent::~fsITransformationComponent()
{
	delete mTransformation;<--- Class 'fsITransformationComponent' does not have a copy constructor which is recommended since it has dynamic memory/resource management.<--- Class 'fsITransformationComponent' does not have a operator= which is recommended since it has dynamic memory/resource management.
}