Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RuntimeLuaProcessing.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RuntimeLuaProcessing.h
19  * @brief       This is the header file for the LuaProcessing class.
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RUNTIME_LUA_PROCESSING_H_
23 #define _FUI_EFFECTS_INTERNAL_RUNTIME_LUA_PROCESSING_H_
24
25 #include <unique_ptr.h>
26 #include <string>
27 #include <list>
28 #include <utility>
29 #include <FUiEffectsTypes.h>
30 #include <lua.hpp>
31 #include "FUiEffects_RuntimeIScriptProcessing.h"
32 #include "FUiEffects_RuntimeModel.h"
33 #include "FUiEffects_RuntimeEffectModelScript.h"
34 #include "FUiEffects_RuntimeIEffectModelScript.h"
35
36 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
37 {
38
39 struct LuaClose
40 {
41         void operator()(lua_State* pLua) const
42         {
43                 lua_close(pLua);
44         }
45 };
46
47 class EffectModel;
48 class EffectModelScript;
49
50 /**
51  * @class       LuaProcessing
52  * @brief       This class executes relevant lua script functions
53  *
54  * @since 2.0
55  *
56  */
57 class LuaProcessing
58         : public IScriptProcessing
59 {
60
61 public:
62         /**
63          * LuaProcessing default class constructor
64          *
65          * @since 2.0
66          *
67          */
68         LuaProcessing(void);
69
70         /**
71          * LuaProcessing class constructor
72          *
73          * @since 2.0
74          *
75          */
76         LuaProcessing(const char* pPathToScript, IEffectModelScript* pEModel);
77
78         /**
79          * LuaProcessing class destructor
80          *
81          * @since 2.0
82          *
83          */
84         virtual ~LuaProcessing(void);
85
86         /**
87          * Calls OnEffectStart function from script
88          *
89          * @since 2.0
90          *
91          * @remarks             Function is inherited from IScriptProcessing interface;
92          *                              if script function performs successfully (with no errors),
93          *                              the function returns true, otherwise returns false
94          */
95         virtual bool OnEffectStart(const EffectsVector<float>& effectStartInfo);
96
97         /**
98          * Calls OnEffectCalculate function from script
99          *
100          * @since 2.0
101          *
102          * @remarks             Function is inherited from IScriptProcessing interface;
103          *                              if script function performs successfully (with no errors),
104          *                              the function returns true, otherwise returns false
105          */
106         virtual bool OnEffectCalculate(float dt);
107
108         /**
109          * Calls OnTouchPressed function from script for handling touch pressed event
110          *
111          * @since 2.0
112          *
113          * @remarks             Function is inherited from IScriptProcessing interface;
114          *                              if script function performs successfully (with no errors),
115          *                              the function returns true, otherwise returns false
116          */
117         virtual bool OnTouchPressed(const TouchEventScript& position);
118
119         /**
120          * Calls OnTouchDoublePressed function from script for handling touch double pressed event
121          *
122          * @since 2.0
123          *
124          * @remarks             Function is inherited from IScriptProcessing interface;
125          *                              if script function performs successfully (with no errors),
126          *                              the function returns true, otherwise returns false
127          */
128         virtual bool OnTouchDoublePressed(const TouchEventScript& position);
129
130         /**
131          * Calls OnTouchMoved function from script for handling touch moved event
132          *
133          * @since 2.0
134          *
135          * @remarks             Function is inherited from IScriptProcessing interface;
136          *                              if script function performs successfully (with no errors),
137          *                              the function returns true, otherwise returns false
138          */
139         virtual bool OnTouchMoved(const TouchEventScript& position);
140
141         /**
142          * Calls OnTouchReleased function from script for handling touch released event
143          *
144          * @since 2.0
145          *
146          * @remarks             Function is inherited from IScriptProcessing interface;
147          *                              if script function performs successfully (with no errors),
148          *                              the function returns true, otherwise returns false
149          */
150         virtual bool OnTouchReleased(const TouchEventScript& position);
151
152         /**
153          * Calls IsEffectFinished function from script
154          *
155          * @since 2.0
156          *
157          */
158         virtual ::Tizen::Ui::Effects::_Runtime::EffectResultS IsEffectFinished(void);
159
160         /**
161          * Calls Initialize function from script
162          *
163          * @since 2.0
164          *
165          * @remarks             Function is inherited from IScriptProcessing interface;
166          *                              if script function performs successfully (with no errors),
167          *                              the function returns true, otherwise returns false
168          */
169         virtual bool Initialize(void);
170
171 private:
172         /**
173          * Hidden copy constructor
174          *
175          * @since 2.0
176          *
177          */
178         LuaProcessing(const LuaProcessing& rhs);
179
180         /**
181          * Hidden assignment operator
182          *
183          * @since 2.0
184          *
185          */
186         LuaProcessing &operator=(const LuaProcessing& rhs);
187
188         /**
189          * Auxiliary function for calling touch events handling script functions
190          *
191          * @since 2.0
192          *
193          */
194         bool OnTouchEvent(const char* pFunName, const TouchEventScript& position);
195
196         /**
197          * Function for calling lua script function
198          *
199          * @since 2.0
200          *
201          */
202         static int CallFunction(const char* pFunctionName, int argsCount, int resultsCount, lua_State* pLua);
203
204 private:
205
206         std::unique_ptr<lua_State, LuaClose> __pLua;            /**< pointer to structure that keeps the whole state of a Lua interpreter*/
207         std::unique_ptr<EffectModelScript> __pEMScript;         /**< pointer to instance of class EffectModelScript (for calling C++ functions from scripts)*/
208
209         static const char* __pStringLua;        /**< contains a simple lua code for transmitting to lua-global variable the pointer to EffectModelScript (performs once in constructor)*/
210
211 }; // LuaProcessing
212
213 } } } } // Tizen::Ui::Effects::_Runtime
214
215 #endif //_FUI_EFFECTS_INTERNAL_RUNTIME_LUA_PROCESSING_H_