1 /* -------------------------------------------------------
2 Copyright (c) 2011 Alberto G. Salguero (alberto.salguero (at) uca.es)
3 
4 Permission is hereby granted, free of charge, to any
5 person obtaining a copy of this software and associated
6 documentation files (the "Software"), to deal in the
7 Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the
10 Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice
14 shall be included in all copies or substantial portions of
15 the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
21 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 ------------------------------------------------------- */
26 #pragma once
27 #include "ICSPrerequisites.h"
28 #include "ICSChannel.h"
29 #include "ICSControlListener.h"
30 
31 namespace ICS
32 {
33 
34 	class DllExport Control
35 	{
36 	public:
37 
38 		enum ControlChangingDirection
39 		{
40 			// If both increase and decrease keys are active at the same time, direction needs to be INCREASE&DECREASE,
41 			// resulting in no action
42 			DECREASE = 0x01, STOP = 0, INCREASE = 0x04
43 		};
44 
45 		Control(const std::string name, bool autoChangeDirectionOnLimitsAfterStop = false, bool autoReverseToInitialValue = false, float initialValue = 0.5, float stepSize = 0.1, float stepsPerSeconds = 2.0, bool axisBindable = true, bool inverted = false);
46 		~Control();
47 
48 		void setChangingDirection(ControlChangingDirection direction);
removeChangingDirection(ControlChangingDirection direction)49 		inline void removeChangingDirection(ControlChangingDirection direction){ currentChangingDirection &= ~direction; };
50 
51 		void setValue(float value);
getValue()52 		inline float getValue(){ return mValue; };
getInitialValue()53 		inline float getInitialValue(){ return mInitialValue; };
54 
setInverted(bool inverted)55 		void setInverted(bool inverted) { mInverted = inverted; }
getInverted()56 		bool getInverted() { return mInverted; }
57 
58 		void attachChannel(Channel* channel, Channel::ChannelDirection direction, float percentage = 1.0);
getAttachedChannels()59 		std::list<Channel*> getAttachedChannels(){ return mAttachedChannels; };
60 
getStepSize()61 		inline float getStepSize(){ return mStepSize; };
getStepsPerSeconds()62 		inline float getStepsPerSeconds(){ return mStepsPerSeconds; };
63 
setStepSize(float size)64 		void setStepSize(float size){ mStepSize = size; };
setStepsPerSeconds(float steps)65 		void setStepsPerSeconds(float steps){ mStepsPerSeconds = std::min(60.f, steps); };
66 
setIgnoreAutoReverse(bool value)67 		inline void setIgnoreAutoReverse(bool value){ mIgnoreAutoReverse = value; }; // mouse disable autoreverse
isAutoReverseIgnored()68 		inline bool isAutoReverseIgnored(){ return mIgnoreAutoReverse; };
getAutoReverse()69 		inline bool getAutoReverse(){ return mAutoReverseToInitialValue; };
70 
getAutoChangeDirectionOnLimitsAfterStop()71 		inline bool getAutoChangeDirectionOnLimitsAfterStop(){ return mAutoChangeDirectionOnLimitsAfterStop; };
72 
getName()73 		inline std::string getName(){ return mName; };
74 
isAxisBindable()75 		inline bool isAxisBindable(){ return mAxisBindable; };
setAxisBindable(bool value)76 		inline void setAxisBindable(bool value){ mAxisBindable = value; };
77 
addListener(ControlListener * ob)78 		inline void addListener(ControlListener* ob){ mListeners.push_back(ob); };
removeListener(ControlListener * ob)79 	    inline void removeListener(ControlListener* ob){ mListeners.remove(ob); };
80 
81 		void update(float timeSinceLastFrame);
82 
83 	protected:
84 		bool mInverted;
85 		float mValue;
86 		float mInitialValue;
87 		std::string mName;
88 		float mStepSize;
89 		float mStepsPerSeconds;
90 		bool mAutoReverseToInitialValue;
91 		bool mIgnoreAutoReverse;
92 		bool mAutoChangeDirectionOnLimitsAfterStop;
93 		bool mAxisBindable;
94 
95 		int currentChangingDirection;
96 		std::list<Channel*> mAttachedChannels;
97 
98 		std::list<ControlListener*> mListeners;
99 
100 		std::list<Control::ControlChangingDirection> mPendingActions;
101 
102 	protected:
103 
104 		void updateChannels();
105 	    void notifyListeners(float previousValue);
106 
107 	};
108 
109 }
110