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
/********************************************************************
*
*	Created:	17/3/2014   11:05
*
*	File:		fsCButtonComponent.h
*
*	Author:		Mick Waites
*	
*	Purpose:	Control component for a GUI button entity.
*
*********************************************************************/

#ifndef fsCButtonComponenthdr
#define fsCButtonComponenthdr

#include <fsCore/src/fsCUniqueId.h>

#include "../../fsIGestureHandlingComponent.h"

struct fsPoint;
class fsCResourceName;
class fsIFont;
class fsCBrush;

class fsCButtonComponent : public fsIGestureHandlingComponent
{
	friend class fsCComponentFactory;
	friend class gfIAutoTestLevelUserInputComponent;

public:

	struct sButtonEventMsgParam : public fsIMessageDispatcher::sMessageParameters
	{
		fsStr mStr;
		fsCButtonComponent* mParent;
	};

	void brushesReplace(const fsCResourceName& pImageFileName, const fsCResourceName& pDownImageFileName,
	                    const fsPoint& pSize);

	void actionSet(const fsCUniqueId& pActionId, const fsStr& pParamStr);

	fsCEntity* buttonGuiEntityCreate(const fsStr& pEntityName, const fsCResourceName& pImageFileName,
	                                 const fsCResourceName& pDownImageFileName);
	fsCEntity* textButtonGuiEntityCreate(const fsStr& pEntityName, const fsCResourceName& pImageFileName,
	                                     const fsCResourceName& pDownImageFileName, const fsStr& pText, fsIFont* pFont);

	static const fsCUniqueId mTypeId;

protected:

	void defaultSpriteSet();

	fsBool acceptingInputGet() const override;
	fsBool highlightSetDo() override;

	void onTap(const fsPoint& pTapPos) override;

	static fsIComponent* create(fsCEntity* pParent);

	void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;

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

	fsPoint mSize;
	std::shared_ptr<fsCBrush> mBrush;
	std::shared_ptr<fsCBrush> mOverBrush;

	fsCUniqueId mActionId;
	sButtonEventMsgParam mActionParam;

private:

	static const fsCUniqueId mActionUnsetId;

	void spriteInitialise(const fsCVariableTable& pVars);
	void actionInitialise(const fsCVariableTable& pVars);
	void textCreateIfWanted(const fsCVariableTable& pVars) const;

	void actionPerform();
};

#endif