Commit 87fcf735248b99b2b722c7f2ee1df12164807dc4

Authored by Adeel Kazmi
1 parent 111bd362

Fixed orientation support in motion blur & stretch examples

Change-Id: Ie0809b97c98e1855a29472df7bb94ae42b0e52e4
examples/motion-blur/motion-blur-example.cpp
1 1 /*
2   - * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -162,6 +162,11 @@ public:
162 162 TOOLBAR_IMAGE,
163 163 APPLICATION_TITLE );
164 164  
  165 + // Ensure the content layer is a square so the touch area works in all orientations
  166 + Vector2 stageSize = Stage::GetCurrent().GetSize();
  167 + float size = std::max( stageSize.width, stageSize.height );
  168 + mContentLayer.SetSize( size, size );
  169 +
165 170 //Add an effects icon on the right of the title
166 171 mActorEffectsButton = Toolkit::PushButton::New();
167 172 mActorEffectsButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON );
... ... @@ -188,11 +193,10 @@ public:
188 193 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE );
189 194 winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
190 195 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
  196 + winHandle.ResizedSignal().Connect( this, &MotionBlurExampleApp::OnWindowResized );
191 197  
192 198 // set initial orientation
193   - unsigned int degrees = 0;
194   - Rotate( static_cast< DeviceOrientation >( degrees ) );
195   -
  199 + Rotate( PORTRAIT );
196 200  
197 201 ///////////////////////////////////////////////////////
198 202 //
... ... @@ -200,7 +204,6 @@ public:
200 204 //
201 205  
202 206 // Scale down actor to fit on very low resolution screens with space to interact:
203   - Size stageSize = Stage::GetCurrent().GetSize();
204 207 mMotionBlurActorSize = Size( std::min( stageSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH ), std::min( stageSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT ) );
205 208 mMotionBlurActorSize = Size( std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) );
206 209  
... ... @@ -220,16 +223,21 @@ public:
220 223  
221 224 }
222 225  
  226 + //////////////////////////////////////////////////////////////
  227 + //
  228 + // Device Orientation Support
  229 + //
  230 + //
  231 +
  232 + void OnWindowResized( Window::WindowSize size )
  233 + {
  234 + Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
  235 + }
  236 +
223 237 void Rotate( DeviceOrientation orientation )
224 238 {
225 239 // Resize the root actor
226   - Vector2 stageSize = Stage::GetCurrent().GetSize();
227   - Vector2 targetSize = stageSize;
228   - if( orientation == LANDSCAPE ||
229   - orientation == LANDSCAPE_INVERSE )
230   - {
231   - targetSize = Vector2( stageSize.y, stageSize.x );
232   - }
  240 + const Vector2 targetSize = Stage::GetCurrent().GetSize();
233 241  
234 242 if( mOrientation != orientation )
235 243 {
... ... @@ -240,15 +248,12 @@ public:
240 248 {
241 249 // has parent so we expect it to be on stage, start animation
242 250 mRotateAnimation = Animation::New( ORIENTATION_DURATION );
243   - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT );
244 251 mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width );
245 252 mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height );
246 253 mRotateAnimation.Play();
247 254 }
248 255 else
249 256 {
250   - // set the rotation to match the orientation
251   - mView.SetOrientation( Degree( -orientation ), Vector3::ZAXIS );
252 257 mView.SetSize( targetSize );
253 258 }
254 259 }
... ...
examples/motion-stretch/motion-stretch-example.cpp
1 1 /*
2   - * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -141,6 +141,11 @@ public:
141 141 TOOLBAR_IMAGE,
142 142 APPLICATION_TITLE );
143 143  
  144 + // Ensure the content layer is a square so the touch area works in all orientations
  145 + Vector2 stageSize = Stage::GetCurrent().GetSize();
  146 + float size = std::max( stageSize.width, stageSize.height );
  147 + mContentLayer.SetSize( size, size );
  148 +
144 149 //Add an slideshow icon on the right of the title
145 150 mActorEffectsButton = Toolkit::PushButton::New();
146 151 mActorEffectsButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON );
... ... @@ -168,10 +173,10 @@ public:
168 173 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE );
169 174 winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
170 175 winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
  176 + winHandle.ResizedSignal().Connect( this, &MotionStretchExampleApp::OnWindowResized );
171 177  
172   - unsigned int degrees = 0;
173   - Rotate( static_cast< DeviceOrientation >( degrees ) );
174   -
  178 + // set initial orientation
  179 + Rotate( PORTRAIT );
175 180  
176 181 ///////////////////////////////////////////////////////
177 182 //
... ... @@ -197,16 +202,15 @@ public:
197 202 //
198 203 //
199 204  
  205 + void OnWindowResized( Window::WindowSize size )
  206 + {
  207 + Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
  208 + }
  209 +
200 210 void Rotate( DeviceOrientation orientation )
201 211 {
202 212 // Resize the root actor
203   - Vector2 stageSize = Stage::GetCurrent().GetSize();
204   - Vector2 targetSize = stageSize;
205   - if( orientation == LANDSCAPE ||
206   - orientation == LANDSCAPE_INVERSE )
207   - {
208   - targetSize = Vector2( stageSize.y, stageSize.x );
209   - }
  213 + const Vector2 targetSize = Stage::GetCurrent().GetSize();
210 214  
211 215 if( mOrientation != orientation )
212 216 {
... ... @@ -217,15 +221,12 @@ public:
217 221 {
218 222 // has parent so we expect it to be on stage, start animation
219 223 mRotateAnimation = Animation::New( ORIENTATION_DURATION );
220   - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -orientation ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT );
221 224 mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width );
222 225 mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height );
223 226 mRotateAnimation.Play();
224 227 }
225 228 else
226 229 {
227   - // set the rotation to match the orientation
228   - mView.SetOrientation( Degree( -orientation ), Vector3::ZAXIS );
229 230 mView.SetSize( targetSize );
230 231 }
231 232 }
... ...