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

#ifndef fsCRollOverButtonComponenthdr
#define fsCRollOverButtonComponenthdr

#include <fsAppCore/src/components/fsITutorialEnabledComponent.h>

#include <fsCore/src/fsCUniqueId.h>

#include "../../../../fsIInputManager.h"
#include "../../fsIMessageListenerComponent.h"

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


class fsCRollOverButtonComponent : public fsIMessageListenerComponent, public fsITutorialEnabledComponent
{
	friend class gfCLevelSequencerMapComponent;
	friend class fsCComponentFactory;
	friend class gfIAutoTestLevelUserInputComponent;

public:

	struct fsCRollOverAction
	{
		virtual void update() = 0;
		virtual void start(const fsPoint& pMousePos) = 0;
		virtual void end(const fsPoint& pMousePos) = 0;
		virtual void mouseDown(const fsPoint& pMousePos) = 0;
		virtual void mouseUp(const fsPoint& pMousePos) = 0;

		fsCRollOverAction()
		{
		}

		virtual ~fsCRollOverAction()
		{
		}
	};

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

	void actionSet(fsCRollOverAction* pRollOverAction);

	fsCEntity* buttonGuiEntityCreate(const fsStr& pEntityName, const fsCResourceName& pImageFileName,
	                                 const fsCResourceName& pDownImageFileName);

	static const fsCUniqueId mTypeId;

protected:

	void tutorialCompletedDo(const fsPoint& pPos) override;

	void updateDo(fsS32 pDeltaMs) override;

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


	void defaultSpriteSet();

	virtual fsBool acceptingInputGet() const;

	virtual void onTap(const fsPoint& pTapPos);

	static fsIComponent* create(fsCEntity* pParent);

	void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;

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

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

	fsCRollOverAction* mActionId;

private:

	fsBool mOver;

	static const fsCUniqueId mActionUnsetId;

	fsBool hitTest(const fsPoint& pPos) const;

	fsBool pointerMoveProcess(const fsIInputManager::sPointerMsgParam& pParam);
	fsBool pointerDownProcess(const fsIInputManager::sPointerMsgParam& pParam);
	fsBool pointerUpProcess(const fsIInputManager::sPointerMsgParam& pParam);

	void spriteInitialise(const fsCVariableTable& pVars);
};

#endif