2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/dali.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include "shared/view.h"
21 #include "radial-sweep-view.h"
22 #include "radial-sweep-view-impl.h"
25 using namespace Dali::Toolkit;
29 const char* TEST_OUTER_RING_FILENAME = DALI_IMAGE_DIR "layer2.png"; // Image to be masked
30 const char* TEST_INNER_RING_FILENAME = DALI_IMAGE_DIR "layer1.png"; // Image to be masked
31 const char* TEST_MENU_FILENAME = DALI_IMAGE_DIR "layer3.png"; // Image to be masked
32 const char* TEST_DIAL_FILENAME = DALI_IMAGE_DIR "layer4.png"; // Image to be masked
33 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); // Background for toolbar
34 const char* APPLICATION_TITLE( "Radial Menu" );
35 const char * const PLAY_ICON( DALI_IMAGE_DIR "icon-play.png" );
36 const char * const STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
40 /********************************************************************************
41 * Application controller class
44 // This example shows how to create a mesh actor for use as a stencil buffer
45 class RadialMenuExample : public ConnectionTracker
50 * @param[in] app The application handle
52 RadialMenuExample(Application app);
62 * Initialization signal handler - all actor initialization should happen here
63 * @param[in] app The application handle
65 void OnInit(Application& app);
68 * Create a sweep view with the given image and parameters
70 RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final );
72 void StartAnimation();
74 bool OnButtonClicked( Toolkit::Button button );
76 void OnAnimationFinished( Animation& source );
79 * Main key event handler
81 * @param[in] event The key event to respond to
83 void OnKeyEvent(const KeyEvent& event);
85 private: // Member variables
93 Application mApplication; ///< The application handle
94 Toolkit::View mView; ///< The toolbar view
95 Layer mContents; ///< The toolbar contents pane
96 ImageActor mImageActor; ///< Image actor shown by stencil mask
98 AnimState mAnimationState;
102 Toolkit::PushButton mPlayStopButton;
103 ImageActor mDialActor;
104 RadialSweepView mRadialSweepView1;
105 RadialSweepView mRadialSweepView2;
106 RadialSweepView mRadialSweepView3;
109 RadialMenuExample::RadialMenuExample(Application app)
110 : mApplication( app ),
111 mAnimationState(STOPPED)
113 // Connect to the Application's Init signal
114 app.InitSignal().Connect(this, &RadialMenuExample::OnInit);
117 RadialMenuExample::~RadialMenuExample()
119 // Nothing to do here; actor handles will clean up themselves.
122 void RadialMenuExample::OnInit(Application& app)
124 DemoHelper::RequestThemeChange();
126 Stage stage = Dali::Stage::GetCurrent();
128 // The Init signal is received once (only) during the Application lifetime
129 stage.KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent);
131 // Create toolbar & view
132 Toolkit::ToolBar toolBar;
133 mContents = DemoHelper::CreateView( mApplication,
140 mIconPlay = ResourceImage::New( PLAY_ICON );
141 mIconStop = ResourceImage::New( STOP_ICON );
142 mPlayStopButton = Toolkit::PushButton::New();
143 mPlayStopButton.SetBackgroundImage( mIconStop );
145 mPlayStopButton.ClickedSignal().Connect( this, &RadialMenuExample::OnButtonClicked );
147 toolBar.AddControl( mPlayStopButton,
148 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
149 Toolkit::Alignment::HorizontalRight,
150 DemoHelper::DEFAULT_PLAY_PADDING );
152 Vector2 imgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME);
153 Vector2 stageSize = stage.GetSize();
154 float minStageDimension = std::min(stageSize.width, stageSize.height);
156 if(stageSize.height <= stageSize.width)
158 minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f;
160 float scale = minStageDimension / imgSize.width;
162 mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f));
163 mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f));
164 mRadialSweepView3 = CreateSweepView( TEST_MENU_FILENAME, Degree(100.0f), Degree(0.0f));
165 mRadialSweepView3.SetInitialActorAngle(Degree(-110));
166 mRadialSweepView3.SetFinalActorAngle(Degree(0));
168 Image dial = ResourceImage::New( TEST_DIAL_FILENAME );
169 mDialActor = ImageActor::New( dial );
170 mDialActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
171 mDialActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
172 mDialActor.SetScale(scale);
173 Layer dialLayer = Layer::New();
175 dialLayer.Add(mDialActor);
176 dialLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
177 dialLayer.SetSize(stage.GetSize());
178 mContents.Add(dialLayer);
180 mRadialSweepView1.SetScale(scale);
181 mRadialSweepView2.SetScale(scale);
182 mRadialSweepView3.SetScale(scale);
187 void RadialMenuExample::StartAnimation()
189 mDialActor.SetOpacity(0.0f);
190 mRadialSweepView1.SetOpacity(0.0f);
191 mAnimation = Animation::New(6.0f);
192 mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f);
193 mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f);
194 mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f);
195 mAnimation.AnimateTo( Property( mDialActor, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.8f ) );
196 mAnimation.AnimateTo( Property( mRadialSweepView1, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.5f ) );
197 mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished );
199 mAnimationState = PLAYING;
203 bool RadialMenuExample::OnButtonClicked( Toolkit::Button button )
205 switch( mAnimationState )
210 mPlayStopButton.SetBackgroundImage( mIconPlay );
217 mPlayStopButton.SetBackgroundImage( mIconStop );
223 mPlayStopButton.SetBackgroundImage( mIconStop );
224 mRadialSweepView1.Deactivate();
225 mRadialSweepView2.Deactivate();
226 mRadialSweepView3.Deactivate();
233 void RadialMenuExample::OnAnimationFinished( Animation& source )
235 mAnimationState = STOPPED;
236 mPlayStopButton.SetBackgroundImage( mIconPlay );
239 RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
244 Image image = ResourceImage::New(imageName);
245 mImageActor = ImageActor::New(image);
246 mImageActor.SetParentOrigin(ParentOrigin::CENTER);
247 mImageActor.SetAnchorPoint(AnchorPoint::CENTER);
248 mImageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
250 // Create the stencil
251 Vector2 imageSize = ResourceImage::GetImageSize(imageName);
252 float diameter = std::max(imageSize.width, imageSize.height);
253 RadialSweepView radialSweepView = RadialSweepView::New();
254 radialSweepView.SetDiameter( diameter );
255 radialSweepView.SetInitialAngle( initialAngle );
256 radialSweepView.SetFinalAngle( finalAngle );
257 radialSweepView.SetInitialSector( Degree(0.0f) );
258 radialSweepView.SetFinalSector( Degree(359.999f) );
259 radialSweepView.SetSize( Stage::GetCurrent().GetSize());
260 radialSweepView.SetEasingFunction( Dali::AlphaFunctions::EaseInOut );
261 radialSweepView.SetPositionInheritanceMode(USE_PARENT_POSITION);
262 mContents.Add(radialSweepView);
263 radialSweepView.Add( mImageActor );
264 mImageActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
266 return radialSweepView;
270 void RadialMenuExample::OnKeyEvent(const KeyEvent& event)
272 if(event.state == KeyEvent::Down)
274 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
281 void RunTest(Application app)
283 RadialMenuExample test(app);
288 // Entry point for Linux & Tizen applications
289 int main(int argc, char **argv)
291 Application app = Application::New(&argc, &argv);