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:	31/3/2014   14:38
*
*	File:		fsCSliderComponent.h
*
*	Author:		Mick Waites
*	
*	Purpose:	Gui element generally used for volume settings.
*
*********************************************************************/

#ifndef fsCSliderComponenthdr
#define fsCSliderComponenthdr

#include <fsCore/src/fsCUniqueId.h>

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

class fsCBrush;


class fsCSliderComponent : public fsIGestureHandlingComponent
{
	friend class fsCComponentFactory;

public:

	struct sSliderMsgParam : public fsIMessageDispatcher::sMessageParameters
	{
		sSliderMsgParam(const fsStr& pParentName) : mParentName(pParentName), mValue(0.0f)
		{
		}

		const fsStr& mParentName;
		fsF32 mValue;
	};

	static const fsCUniqueId mTypeId;

	static const fsCUniqueId mEventSliderMovedMsg;
	static const fsCUniqueId mEventSliderReleasedMsg;

	void valueSet(fsF32 pValue);

protected:

	void initialiseDo() override;
	fsBool acceptingInputGet() const override;
	fsBool highlightSetDo() override;
	void onDragStart(const fsPoint& pStartPos) override;
	void onDragMove(const fsPoint& pCurrPos) override;
	void onDragEnd(const fsPoint& pEndPos) override;

	static fsIComponent* create(fsCEntity* pParent);

	void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;

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

	sSliderMsgParam mMessageParams;

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

	fsVec2d mOrigPointerPos;

	fsPoint mKnobLeftPos;
	fsF32 mRange;
	fsF32 mOrigValue;

	fsBool mPointerOver;
	fsBool mWaitingForPointerUp;
	fsBool mArc;

private:

	void spriteInitialise(const fsCVariableTable& pVars);
	void rangeAndPosInitialise(const fsCVariableTable& pVars);
	void knobPositionSetByValue();
};

#endif