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
/********************************************************************
*
*	File:		fsCBarGuiComponent.h
*
*	Purpose:	Bar that refills / empties
*
*********************************************************************/

#ifndef fsCBarGuiComponenthdr
#define fsCBarGuiComponenthdr

#include <fsCore/src/fsCUniqueId.h>

#include "fsIMessageListenerGuiComponent.h"
#include "fsRenderer/src/fsCSprite.h"

class fsCEntity;
class fsINode;

class fsCBarGuiComponent : public fsIMessageListenerGuiComponent
{
	friend class fsCComponentFactory;
	friend class fsIDebug;

public:

	static const fsCUniqueId mTypeId;

	void timeInit(fsS32 pFillDelay);
	fsBool inputDisabled() const;
	void drain();
	fsBool timerActive() const;

protected:

	void serialiseDo() override;
	void deserialiseDo() override;

	void renderDo() override;
	void updateDo(fsS32 pDeltaMs) override;
	void matrixApplyDo() override;
	
	void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;

	void listenersRegisterDo() override;
	void listenersDeregisterDo() override;
	fsBool messageProcessDo(const fsCUniqueId& pMessageType,
							const fsIMessageDispatcher::sMessageParameters& pParam) override;

	static fsIComponent* create(fsCEntity* pParent);

	fsCBarGuiComponent(fsCEntity* pParent);
	virtual ~fsCBarGuiComponent();<--- Destructor in derived class

private:

	enum
	{
		eDIRECTION_UP = 0,
		eDIRECTION_DOWN,
		eDIRECTION_RIGHT,
		eDIRECTION_LEFT
	};

	fsBool mLevelComplete;

	fsITextSpriteComponent* mTimeTxt;

	std::unique_ptr<fsCSprite> mDisabledSprite;
	std::unique_ptr<fsCSprite> mFillSprite;
	std::shared_ptr<fsCBrush> mFillBrush;

	fsAffineMtx2d mLocalMtx;

	fsF32 mCurrentFillPercent;
	fsS32 mPrevFillLength;

	fsS32 mFillDirection;

	fsS32 mTimeToFillMs;
	fsS32 mCurrentFillMs;

	fsS32 mRecharge;
	fsBool mStartsFull;

	fsPoint mFillSprPos;

	void spritesInitialise(const fsCVariableTable& pVars);
	void fillDirectionInitialise(const fsCVariableTable& pVars);
	void fillValuesInitialise(const fsCVariableTable& pVars);
	void fillSpriteUpdate();
	fsS32 fillLengthCalculate() const;
	void fillValuesUpdate();

};

#endif