Merge "Size negotiation patch 1: Remove SetPreferred size" into tizen
[platform/core/uifw/dali-demo.git] / examples / radial-menu / radial-menu-example.cpp
index 4067e64..40bf308 100644 (file)
@@ -1,22 +1,23 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include "../shared/view.h"
+#include "shared/view.h"
 #include "radial-sweep-view.h"
 #include "radial-sweep-view-impl.h"
 
@@ -120,8 +121,10 @@ RadialMenuExample::~RadialMenuExample()
 
 void RadialMenuExample::OnInit(Application& app)
 {
+  Stage stage = Dali::Stage::GetCurrent();
+
   // The Init signal is received once (only) during the Application lifetime
-  Stage::GetCurrent().KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent);
+  stage.KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent);
 
   // Create toolbar & view
   Toolkit::ToolBar toolBar;
@@ -132,8 +135,8 @@ void RadialMenuExample::OnInit(Application& app)
                                       TOOLBAR_IMAGE,
                                       APPLICATION_TITLE );
 
-  mIconPlay = Image::New( PLAY_ICON );
-  mIconStop = Image::New( STOP_ICON );
+  mIconPlay = ResourceImage::New( PLAY_ICON );
+  mIconStop = ResourceImage::New( STOP_ICON );
   mPlayStopButton = Toolkit::PushButton::New();
   mPlayStopButton.SetBackgroundImage( mIconStop );
 
@@ -144,8 +147,15 @@ void RadialMenuExample::OnInit(Application& app)
                       Toolkit::Alignment::HorizontalRight,
                       DemoHelper::DEFAULT_PLAY_PADDING );
 
-  Vector2 imgSize = Image::GetImageSize(TEST_OUTER_RING_FILENAME);
-  float scale = Stage::GetCurrent().GetSize().width / imgSize.width;
+  Vector2 imgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME);
+  Vector2 stageSize = stage.GetSize();
+  float minStageDimension = std::min(stageSize.width, stageSize.height);
+
+  if(stageSize.height <= stageSize.width)
+  {
+    minStageDimension -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f;
+  }
+  float scale = minStageDimension / imgSize.width;
 
   mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f));
   mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f),  Degree(0.0f));
@@ -153,15 +163,16 @@ void RadialMenuExample::OnInit(Application& app)
   mRadialSweepView3.SetInitialActorAngle(Degree(-110));
   mRadialSweepView3.SetFinalActorAngle(Degree(0));
 
-  Image dial = Image::New( TEST_DIAL_FILENAME );
+  Image dial = ResourceImage::New( TEST_DIAL_FILENAME );
   mDialActor = ImageActor::New( dial );
+  mDialActor.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
   mDialActor.SetPositionInheritanceMode(USE_PARENT_POSITION);
   mDialActor.SetScale(scale);
   Layer dialLayer = Layer::New();
 
   dialLayer.Add(mDialActor);
   dialLayer.SetPositionInheritanceMode(USE_PARENT_POSITION);
-  dialLayer.SetSize(Stage::GetCurrent().GetSize());
+  dialLayer.SetSize(stage.GetSize());
   mContents.Add(dialLayer);
 
   mRadialSweepView1.SetScale(scale);
@@ -179,8 +190,8 @@ void RadialMenuExample::StartAnimation()
   mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f);
   mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f);
   mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f);
-  mAnimation.OpacityTo(mDialActor, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.8f);
-  mAnimation.OpacityTo(mRadialSweepView1, 1.0f, AlphaFunctions::EaseIn, 0.0f, 0.5f);
+  mAnimation.AnimateTo( Property( mDialActor, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.8f ) );
+  mAnimation.AnimateTo( Property( mRadialSweepView1, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunctions::EaseIn, TimePeriod( 0.0f, 0.5f ) );
   mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished );
 
   mAnimationState = PLAYING;
@@ -228,13 +239,15 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName,
                                                     Degree finalAngle)
 {
   // Create the image
-  Image image = Image::New(imageName);
+  Image image = ResourceImage::New(imageName);
   mImageActor = ImageActor::New(image);
   mImageActor.SetParentOrigin(ParentOrigin::CENTER);
   mImageActor.SetAnchorPoint(AnchorPoint::CENTER);
+  mImageActor.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS );
 
   // Create the stencil
-  float diameter = std::max(image.GetWidth(), image.GetHeight());
+  Vector2 imageSize = ResourceImage::GetImageSize(imageName);
+  float diameter = std::max(imageSize.width, imageSize.height);
   RadialSweepView radialSweepView = RadialSweepView::New();
   radialSweepView.SetDiameter( diameter );
   radialSweepView.SetInitialAngle( initialAngle );