2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <dali/dali.h>
18 #include <dali-toolkit/dali-toolkit.h>
19 #include "../shared/view.h"
20 #include "radial-sweep-view.h"
21 #include "radial-sweep-view-impl.h"
24 using namespace Dali::Toolkit;
28 const char* TEST_OUTER_RING_FILENAME = DALI_IMAGE_DIR "layer2.png"; // Image to be masked
29 const char* TEST_INNER_RING_FILENAME = DALI_IMAGE_DIR "layer1.png"; // Image to be masked
30 const char* TEST_MENU_FILENAME = DALI_IMAGE_DIR "layer3.png"; // Image to be masked
31 const char* TEST_DIAL_FILENAME = DALI_IMAGE_DIR "layer4.png"; // Image to be masked
32 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); // Background for toolbar
33 const char* APPLICATION_TITLE( "Radial Menu" );
34 const char * const PLAY_ICON( DALI_IMAGE_DIR "icon-play.png" );
35 const char * const STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
39 /********************************************************************************
40 * Application controller class
43 // This example shows how to create a mesh actor for use as a stencil buffer
44 class RadialMenuExample : public ConnectionTracker
49 * @param[in] app The application handle
51 RadialMenuExample(Application app);
61 * Initialization signal handler - all actor initialization should happen here
62 * @param[in] app The application handle
64 void OnInit(Application& app);
67 * Create a sweep view with the given image and parameters
69 RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final );
71 void StartAnimation();
73 bool OnButtonClicked( Toolkit::Button button );
75 void OnAnimationFinished( Animation& source );
78 * Main key event handler
80 * @param[in] event The key event to respond to
82 void OnKeyEvent(const KeyEvent& event);
84 private: // Member variables
92 Application mApplication; ///< The application handle
93 Toolkit::View mView; ///< The toolbar view
94 Layer mContents; ///< The toolbar contents pane
95 ImageActor mImageActor; ///< Image actor shown by stencil mask
97 AnimState mAnimationState;
101 Toolkit::PushButton mPlayStopButton;
102 ImageActor mDialActor;
103 RadialSweepView mRadialSweepView1;
104 RadialSweepView mRadialSweepView2;
105 RadialSweepView mRadialSweepView3;
108 RadialMenuExample::RadialMenuExample(Application app)
109 : mApplication( app ),
110 mAnimationState(STOPPED)
112 // Connect to the Application's Init signal
113 app.InitSignal().Connect(this, &RadialMenuExample::OnInit);
116 RadialMenuExample::~RadialMenuExample()
118 // Nothing to do here; actor handles will clean up themselves.
121 void RadialMenuExample::OnInit(Application& app)
123 // The Init signal is received once (only) during the Application lifetime
124 Stage::GetCurrent().KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent);
126 // Create toolbar & view
127 Toolkit::ToolBar toolBar;
128 mContents = DemoHelper::CreateView( mApplication,
135 mIconPlay = Image::New( PLAY_ICON );
136 mIconStop = Image::New( STOP_ICON );
137 mPlayStopButton = Toolkit::PushButton::New();
138 mPlayStopButton.SetBackgroundImage( mIconStop );
140 mPlayStopButton.ClickedSignal().Connect( this, &RadialMenuExample::OnButtonClicked );
142 toolBar.AddControl( mPlayStopButton,
143 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
144 Toolkit::Alignment::HorizontalRight,
145 DemoHelper::DEFAULT_PLAY_PADDING );
147 Vector2 imgSize = Image::GetImageSize(TEST_OUTER_RING_FILENAME);
148 float scale = Stage::GetCurrent().GetSize().width / imgSize.width;
150 mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f));
151 mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f));
152 mRadialSweepView3 = CreateSweepView( TEST_MENU_FILENAME, Degree(100.0f), Degree(0.0f));
153 mRadialSweepView3.SetInitialActorAngle(Degree(-110));
154 mRadialSweepView3.SetFinalActorAngle(Degree(0));
156 Image dial = Image::New( TEST_DIAL_FILENAME );
157 mDialActor = ImageActor::New( dial );
158 mDialActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
159 mDialActor.SetScale(scale);
160 Layer dialLayer = Layer::New();
162 dialLayer.Add(mDialActor);
163 dialLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
164 dialLayer.SetSize(Stage::GetCurrent().GetSize());
165 mContents.Add(dialLayer);
167 mRadialSweepView1.SetScale(scale);
168 mRadialSweepView2.SetScale(scale);
169 mRadialSweepView3.SetScale(scale);
174 void RadialMenuExample::StartAnimation()
176 mDialActor.SetOpacity(0.0f);
177 mRadialSweepView1.SetOpacity(0.0f);
178 mAnimation = Animation::New(6.0f);
179 mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f);
180 mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f);
181 mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f);
182 mAnimation.OpacityTo(mDialActor, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.8f);
183 mAnimation.OpacityTo(mRadialSweepView1, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.5f);
184 mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished );
186 mAnimationState = PLAYING;
190 bool RadialMenuExample::OnButtonClicked( Toolkit::Button button )
192 switch( mAnimationState )
197 mPlayStopButton.SetBackgroundImage( mIconPlay );
204 mPlayStopButton.SetBackgroundImage( mIconStop );
210 mPlayStopButton.SetBackgroundImage( mIconStop );
211 mRadialSweepView1.Deactivate();
212 mRadialSweepView2.Deactivate();
213 mRadialSweepView3.Deactivate();
220 void RadialMenuExample::OnAnimationFinished( Animation& source )
222 mAnimationState = STOPPED;
223 mPlayStopButton.SetBackgroundImage( mIconPlay );
226 RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
231 Image image = Image::New(imageName);
232 mImageActor = ImageActor::New(image);
233 mImageActor.SetParentOrigin(ParentOrigin::CENTER);
234 mImageActor.SetAnchorPoint(AnchorPoint::CENTER);
236 // Create the stencil
237 float diameter = std::max(image.GetWidth(), image.GetHeight());
238 RadialSweepView radialSweepView = RadialSweepView::New();
239 radialSweepView.SetDiameter( diameter );
240 radialSweepView.SetInitialAngle( initialAngle );
241 radialSweepView.SetFinalAngle( finalAngle );
242 radialSweepView.SetInitialSector( Degree(0.0f) );
243 radialSweepView.SetFinalSector( Degree(359.999f) );
244 radialSweepView.SetSize( Stage::GetCurrent().GetSize());
245 radialSweepView.SetEasingFunction( Dali::AlphaFunctions::EaseInOut );
246 radialSweepView.SetPositionInheritanceMode(USE_PARENT_POSITION);
247 mContents.Add(radialSweepView);
248 radialSweepView.Add( mImageActor );
249 mImageActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
251 return radialSweepView;
255 void RadialMenuExample::OnKeyEvent(const KeyEvent& event)
257 if(event.state == KeyEvent::Down)
259 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
266 void RunTest(Application app)
268 RadialMenuExample test(app);
273 // Entry point for Linux & Tizen applications
274 int main(int argc, char **argv)
276 Application app = Application::New(&argc, &argv);