Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / EffectsApp / EffectsApp / project / src / TimeBasedSingleEffectForm.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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://www.tizenopensource.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 #include "TimeBasedSingleEffectForm.h"
18 #include <FIo.h>
19 #include <FApp.h>
20 #include <time.h>
21
22 using namespace Osp::Ui::Controls;
23 using namespace Osp::Ui::Effects;
24
25 TimeBasedSingleEffectForm::TimeBasedSingleEffectForm() : EffectsBaseForm()
26 {
27 }
28
29 TimeBasedSingleEffectForm::~TimeBasedSingleEffectForm()
30 {
31 }
32
33 void
34 TimeBasedSingleEffectForm::InitializeEffect()
35 {
36         _pPanel->AddTouchEventListener(*this);
37
38         // Register effect file
39         _pEffect = _pEffectManager->CreateEffect(Osp::App::App::GetInstance()->GetAppResourcePath() + L"paper_timebased.eff");
40
41         // Set the frame as a render target of effects
42         _pEffect->SetRenderTarget(*Osp::App::UiApp::GetInstance()->GetFrameAt(0));
43         _pEffect->SetEffectEventListener(this);
44         _pEffect->SetResourceProvider(this);
45 }
46
47 void
48 TimeBasedSingleEffectForm::OnTouchPressed(const Osp::Ui::Control& source, const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo& touchInfo)
49 {
50 }
51
52 void
53 TimeBasedSingleEffectForm::OnTouchLongPressed(const Osp::Ui::Control& source, const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo& touchInfo)
54 {
55         //Switching to main form:
56         _pEffect->Stop();
57         OnFormBackRequested(*this);
58 }
59
60 void
61 TimeBasedSingleEffectForm::OnTouchMoved(const Osp::Ui::Control& source, const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo& touchInfo)
62 {
63         //Start effect
64         Osp::Base::Collection::ArrayList effectStartInfo;
65         effectStartInfo.Construct();
66
67         srand(time(NULL));
68         Osp::Base::Float randomInfo(rand() * 1.f / RAND_MAX);
69         effectStartInfo.Add(randomInfo);
70         _pEffect->Start(effectStartInfo);
71 }
72