Add post processor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / feedback / feedback-style.h
1 #ifndef DALI_INTERNAL_FEEDBACK_STYLE_H
2 #define DALI_INTERNAL_FEEDBACK_STYLE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/feedback-player.h>
23 #include <dali/public-api/adaptor-framework/style-change.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/connection-tracker.h>
26 #include <dali/public-api/signals/slot-delegate.h>
27 #include <map>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/internal/feedback/feedback-ids.h>
31
32 namespace Dali
33 {
34 namespace Toolkit
35 {
36 namespace Internal
37 {
38 struct FeedbackStyleInfo;
39 struct SignalFeedbackInfo;
40
41 /**
42  * Plays feedback effects for Dali-Toolkit UI Controls.
43  *
44  * This functionality relies on an adaptor plugin.
45  * (And will have no effect if this is not loaded)
46  *
47  */
48 class FeedbackStyle : public ConnectionTracker
49 {
50 public:
51   /**
52    * Constructor.
53    */
54   FeedbackStyle();
55
56   /**
57    * The destructor
58    */
59   ~FeedbackStyle();
60
61   /**
62    * Called to start playing feedback effects.
63    */
64   void Start();
65
66   /**
67    * Called to stop playing feedback effects.
68    */
69   void Stop();
70
71   /**
72    * Callback function to play a feedback effect when a signal is emitted for an object
73    * Plays feedback effect.
74    * @param [in] type The Object type
75    * @param [in] signalName The name of the signal
76    */
77   void PlayFeedback(const std::string& type, const std::string& signalName);
78
79   /**
80    * Connects feedback to signals for the newly created object
81    * @param [in] object Handle to the newly created object
82    */
83   void ObjectCreated(BaseHandle object);
84
85   /**
86    * Style changed so reload the theme file
87    * @param [in] userDefinedThemePath Theme filename path
88    * @param [in] styleChange The type of style change
89    */
90   void StyleChanged(const std::string& userDefinedThemePath, StyleChange::Type styleChange);
91
92 private:
93   /**
94    * Helper to retrieve styleInfo from mStyleInfoLut
95    * @param type A string described a type of object
96    * @return The style information for the given object
97    */
98   const FeedbackStyleInfo& GetStyleInfo(const std::string& type) const;
99
100   /**
101    * Callback function for Dali::Toolkit::PushButton::SignalPressed signal
102    * Plays feedback effect.
103    * @param [in] effect The feedback effect to play
104    */
105   bool LoadTheme(const std::string& data);
106
107   /**
108    * Loads a string representation the theme.
109    * @param [in] data A string represenation of the theme.
110    * @param [in] format The string representation format ie JSON.
111    */
112   void LoadFromString(const std::string& data);
113
114   /**
115    * Helper to store signal information.
116    * @param [in] styleInfo The information will be stored here.
117    * @param [in] signalInfo The information to add.
118    */
119   void AddSignalInfo(FeedbackStyleInfo& styleInfo, SignalFeedbackInfo&& signalInfo);
120
121   /**
122    * Map a pattern string to feedback pattern ID.
123    * @param [in] pattern The pattern string.
124    * @return A feedback pattern ID.
125    */
126   FeedbackPattern GetFeedbackPattern(const std::string& pattern);
127
128   /**
129    * Plays a feedback effect
130    * @param [in] type The feedback type haptic or sound
131    * @param [in] effect The feedback effect to play
132    */
133   void PlayEffect(FeedbackType type, FeedbackPattern effect);
134
135   /**
136    * Plays a haptic or sound effect file
137    * @param [in] type The feedback type haptic or sound
138    * @param [in] file The path to the file containing the effect
139    */
140   void PlayFile(FeedbackType type, const std::string& file);
141
142 private:
143   Dali::FeedbackPlayer mFeedback;
144
145   std::map<const std::string, FeedbackPattern>   mFeedbackPatternLut; ///< Used to convert feedback pattern strings into enumerated values
146   std::map<const std::string, FeedbackStyleInfo> mStyleInfoLut;       ///< Converts key strings into style information
147 };
148
149 } // namespace Internal
150
151 } // namespace Toolkit
152
153 } // namespace Dali
154
155 #endif // DALI_INTERNAL_FEEDBACK_STYLE_H