From: Paul Wisbey Date: Wed, 4 Mar 2015 18:53:01 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/tizen' into new_text X-Git-Tag: new_text_0.1~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a61f04a9bf4241761bda7742918967f34de2891;p=platform%2Fcore%2Fuifw%2Fdali-demo.git Merge remote-tracking branch 'origin/tizen' into new_text Conflicts: build/tizen/examples/CMakeLists.txt demo/dali-demo.cpp examples/buttons/buttons-example.cpp examples/item-view/item-view-example.cpp examples/text-view/text-view-example.cpp Change-Id: I8816d065edca8e2a3fd37cdcedda4b02735f5007 --- 8a61f04a9bf4241761bda7742918967f34de2891 diff --cc demo/dali-demo.cpp index a13fcc4f,a2741e81..e703caca --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@@ -16,7 -16,6 +16,7 @@@ */ #include "dali-table-view.h" - #include "examples/shared/dali-demo-strings.h" ++#include "shared/dali-demo-strings.h" using namespace Dali; @@@ -31,24 -25,25 +31,26 @@@ int main(int argc, char **argv DaliTableView demo(app); - demo.AddExample(Example("bubble-effect.example", "Bubbles")); - demo.AddExample(Example("blocks.example", "Blocks")); - demo.AddExample(Example("cluster.example", "Cluster control")); - demo.AddExample(Example("cube-transition-effect.example", "Cube Transition")); - demo.AddExample(Example("dissolve-effect.example", "Dissolve Transition")); - demo.AddExample(Example("item-view.example", "Item View")); - demo.AddExample(Example("magnifier.example", "Magnifier")); - demo.AddExample(Example("motion-blur.example", "Motion Blur")); - demo.AddExample(Example("motion-stretch.example", "Motion Stretch")); - demo.AddExample(Example("page-turn-view.example", "Page Turn View")); - demo.AddExample(Example("radial-menu.example", "Radial Menu")); - demo.AddExample(Example("refraction-effect.example", "Refraction")); - demo.AddExample(Example("scroll-view.example", "Scroll View")); - demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); - demo.AddExample(Example("builder.example", "Script Based UI")); - demo.AddExample(Example("image-scaling-irregular-grid.example", "Image Scaling Modes")); - demo.AddExample(Example("text-view.example", "Text View")); + demo.AddExample(Example("bubble-effect.example", DALI_DEMO_STR_TITLE_BUBBLES)); + demo.AddExample(Example("blocks.example", DALI_DEMO_STR_TITLE_BLOCKS)); + demo.AddExample(Example("cluster.example", DALI_DEMO_STR_TITLE_CLUSTER)); + demo.AddExample(Example("cube-transition-effect.example", DALI_DEMO_STR_TITLE_CUBE_TRANSITION)); + demo.AddExample(Example("dissolve-effect.example", DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION)); + demo.AddExample(Example("item-view.example", DALI_DEMO_STR_TITLE_ITEM_VIEW)); + demo.AddExample(Example("magnifier.example", DALI_DEMO_STR_TITLE_MAGNIFIER)); + demo.AddExample(Example("motion-blur.example", DALI_DEMO_STR_TITLE_MOTION_BLUR)); + demo.AddExample(Example("motion-stretch.example", DALI_DEMO_STR_TITLE_MOTION_STRETCH)); + demo.AddExample(Example("page-turn-view.example", DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW)); + demo.AddExample(Example("radial-menu.example", DALI_DEMO_STR_TITLE_RADIAL_MENU)); + demo.AddExample(Example("refraction-effect.example", DALI_DEMO_STR_TITLE_REFRACTION)); + demo.AddExample(Example("scroll-view.example", DALI_DEMO_STR_TITLE_SCROLL_VIEW)); + demo.AddExample(Example("shadow-bone-lighting.example", DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS)); + demo.AddExample(Example("builder.example", DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI)); + demo.AddExample(Example("image-scaling-irregular-grid.example", DALI_DEMO_STR_TITLE_IMAGE_SCALING)); + demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)); + demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL)/*TODO - new string*/); + demo.AddExample(Example("animated-shapes.example", "Animated Shapes")); + demo.AddExample(Example("path-animation.example", "Path Animation")); app.MainLoop(); return 0; diff --cc examples/cube-transition-effect/cube-transition-effect-example.cpp index 00000000,00a84971..93e90798 mode 000000,100644..100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@@ -1,0 -1,428 +1,411 @@@ + /* + * 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. + * + */ + + // EXTERNAL INCLUDES + #include + + // INTERNAL INCLUDES + #include "shared/view.h" + + #include + #include + + using namespace Dali; + + // LOCAL STUFF + namespace + { + + const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + const char * const APPLICATION_TITLE_WAVE( "Cube Transition: Wave" ); + const char * const APPLICATION_TITLE_CROSS( "Cube Transition: Cross" ); + const char * const APPLICATION_TITLE_FOLD( "Cube Transition: Fold" ); + const char * const EFFECT_WAVE_IMAGE( DALI_IMAGE_DIR "icon-effect-wave.png" ); + const char * const EFFECT_CROSS_IMAGE( DALI_IMAGE_DIR "icon-effect-cross.png" ); + const char * const EFFECT_FOLD_IMAGE( DALI_IMAGE_DIR "icon-effect-fold.png" ); + const char * const SLIDE_SHOW_START_ICON( DALI_IMAGE_DIR "icon-play.png" ); + const char * const SLIDE_SHOW_STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" ); + + const char* IMAGES[] = + { + DALI_IMAGE_DIR "gallery-large-1.jpg", + DALI_IMAGE_DIR "gallery-large-2.jpg", + DALI_IMAGE_DIR "gallery-large-3.jpg", + DALI_IMAGE_DIR "gallery-large-4.jpg", + DALI_IMAGE_DIR "gallery-large-5.jpg", + DALI_IMAGE_DIR "gallery-large-6.jpg", + DALI_IMAGE_DIR "gallery-large-7.jpg", + DALI_IMAGE_DIR "gallery-large-8.jpg", + DALI_IMAGE_DIR "gallery-large-9.jpg", + DALI_IMAGE_DIR "gallery-large-10.jpg", + DALI_IMAGE_DIR "gallery-large-11.jpg", + DALI_IMAGE_DIR "gallery-large-12.jpg", + DALI_IMAGE_DIR "gallery-large-13.jpg", + DALI_IMAGE_DIR "gallery-large-14.jpg", + DALI_IMAGE_DIR "gallery-large-15.jpg", + DALI_IMAGE_DIR "gallery-large-16.jpg", + DALI_IMAGE_DIR "gallery-large-17.jpg", + DALI_IMAGE_DIR "gallery-large-18.jpg", + DALI_IMAGE_DIR "gallery-large-19.jpg", + DALI_IMAGE_DIR "gallery-large-20.jpg", + DALI_IMAGE_DIR "gallery-large-21.jpg", + }; + const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) ); + + // the number of cubes: NUM_COLUMNS*NUM_ROWS + // better choose the numbers that can divide viewAreaSize.x + const int NUM_COLUMNS_WAVE(16); + const int NUM_COLUMNS_CROSS(8); + const int NUM_COLUMNS_FOLD(8); + // better choose the numbers that can divide viewAreaSize.y + const int NUM_ROWS_WAVE(20); + const int NUM_ROWS_CROSS(10); + const int NUM_ROWS_FOLD(10); + //transition effect duration + const float ANIMATION_DURATION_WAVE(1.5f); + const float ANIMATION_DURATION_CROSS(1.f); + const float ANIMATION_DURATION_FOLD(1.f); + //transition effect displacement + const float CUBE_DISPLACEMENT_WAVE(70.f); + const float CUBE_DISPLACEMENT_CROSS(30.f); + + // The duration of the current image staying on screen when slideshow is on + const int VIEWINGTIME = 2000; // 2 seconds + } // namespace + + class CubeTransitionApp : public ConnectionTracker + { + public: + + /** + * Constructor + * @param application class, stored as reference + */ + CubeTransitionApp( Application& application ); + + ~CubeTransitionApp(); + + private: + + /** + * This method gets called once the main loop of application is up and running + */ + void OnInit( Application& application ); + /** + * PanGesture callback. This method gets called when the pan gesture is detected. + * @param[in] actor The actor receiving the pan gesture. + * @param[in] gesture The detected pan gesture. + */ + void OnPanGesture( Actor actor, const PanGesture& gesture ); + /** + * Load the next image and start the transition; + */ + void GoToNextImage(); + /** + * Callback function of image resource loading succeed + * Start the transition + * @param[in] image The image content of the imageActor for transition + */ + void OnImageLoaded(ResourceImage image); + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event); + /** + * Callback function of effect-switch button + * Change the effect when the effect button is clicked + * @param[in] button The handle of the clicked button + */ + bool OnEffectButtonClicked( Toolkit::Button button ); + /** + * Callback function of slideshow button + * Start or stop the automatical image display when the slideshow button is clicked + * @param[in] button The handle of the clicked button + */ + bool OnSildeshowButtonClicked( Toolkit::Button button ); + /** + * Callback function of cube transition completed signal + * @param[in] effect The cube effect used for the transition + * @param[in] imageActor The target imageActor of the completed transition + */ + void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor); + /** + * Callback function of timer tick + * The timer is used to count the image display duration in slideshow, + */ + bool OnTimerTick(); + + private: + Application& mApplication; + Toolkit::View mView; + Toolkit::ToolBar mToolBar; + Layer mContent; - Toolkit::TextView mTitleActor; + Actor mParent; + + Vector2 mViewSize; + + ImageActor mCurrentImage; + ImageActor mNextImage; + unsigned int mIndex; + bool mIsImageLoading; + Constraint mImageConstraint; + + PanGestureDetector mPanGestureDetector; + + Toolkit::CubeTransitionEffect mCubeWaveEffect; + Toolkit::CubeTransitionEffect mCubeCrossEffect; + Toolkit::CubeTransitionEffect mCubeFoldEffect; + Toolkit::CubeTransitionEffect mCurrentEffect; + + bool mSlideshow; + Timer mViewTimer; + Toolkit::PushButton mSlideshowButton; + Image mIconSlideshowStart; + Image mIconSlideshowStop; + + Vector2 mPanPosition; + Vector2 mPanDisplacement; + + Image mImageWave; + Image mImageCross; + Image mImageFold; + Toolkit::PushButton mEffectChangeButton; + }; + + CubeTransitionApp::CubeTransitionApp( Application& application ) + : mApplication( application ), + mIndex( 0 ), + mIsImageLoading( false ), + mSlideshow( false ) + { + mApplication.InitSignal().Connect( this, &CubeTransitionApp::OnInit ); + } + + CubeTransitionApp::~CubeTransitionApp() + { + //Nothing to do + } + + void CubeTransitionApp::OnInit( Application& application ) + { + Stage::GetCurrent().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent); + + // Creates a default view with a default tool bar, the view is added to the stage. + mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); + + // Add an effect-changing button on the right of the tool bar. + mImageWave = ResourceImage::New( EFFECT_WAVE_IMAGE ); + mImageCross = ResourceImage::New( EFFECT_CROSS_IMAGE ); + mImageFold = ResourceImage::New( EFFECT_FOLD_IMAGE ); + mEffectChangeButton = Toolkit::PushButton::New(); + mEffectChangeButton.SetBackgroundImage(mImageWave); + mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked ); + mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + - // Add title to the tool bar. - mTitleActor = Toolkit::TextView::New(); - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); - + //Add an slideshow icon on the right of the title + mIconSlideshowStart = ResourceImage::New( SLIDE_SHOW_START_ICON ); + mIconSlideshowStop = ResourceImage::New( SLIDE_SHOW_STOP_ICON ); + mSlideshowButton = Toolkit::PushButton::New(); + mSlideshowButton.SetBackgroundImage( mIconSlideshowStart ); + mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked ); + mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + + // Set size to stage size to avoid seeing a black border on transition + mViewSize = Stage::GetCurrent().GetSize(); + + mParent = Actor::New(); + mParent.SetSize( mViewSize ); + mParent.SetPositionInheritanceMode( USE_PARENT_POSITION ); + mContent.Add( mParent ); + + // use pan gesture to detect the cursor or finger movement + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture ); + mPanGestureDetector.Attach( mParent ); + + //use small cubes + mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New(NUM_ROWS_WAVE, NUM_COLUMNS_WAVE, mViewSize); + mCubeWaveEffect.SetTransitionDuration( ANIMATION_DURATION_WAVE ); + mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE ); + mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); + mParent.Add(mCubeWaveEffect.GetRoot()); + // use big cubes + mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS, mViewSize); + mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS); + mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS ); + mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); + mParent.Add(mCubeCrossEffect.GetRoot()); + + mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New(NUM_ROWS_FOLD, NUM_COLUMNS_FOLD, mViewSize); + mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD); + mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); + mParent.Add(mCubeFoldEffect.GetRoot()); + + mViewTimer = Timer::New( VIEWINGTIME ); + mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); + + // show the first image + mImageConstraint = Constraint::New( Actor::Property::Scale, LocalSource( Actor::Property::Size ), ParentSource( Actor::Property::Size ), ScaleToFitKeepAspectRatioConstraint() ); + + mCurrentImage = ImageActor::New( ResourceImage::New( IMAGES[mIndex] ) ); + mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION ); + mCurrentImage.ApplyConstraint( mImageConstraint ); + mParent.Add( mCurrentImage ); + + mCurrentEffect = mCubeWaveEffect; + mCurrentEffect.SetCurrentImage( mCurrentImage ); - - // Set Title text - mTitleActor.SetText( APPLICATION_TITLE_WAVE ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_WAVE ) ); - mTitleActor.SetStyleToCurrentText( DemoHelper::GetDefaultTextStyle() ); + } + + // signal handler, called when the pan gesture is detected + void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) + { + // does not response when the transition has not finished + if( mIsImageLoading || mCubeWaveEffect.IsTransiting() || mCubeCrossEffect.IsTransiting() || mCubeFoldEffect.IsTransiting() || mSlideshow ) + { + return; + } + + if( gesture.state == Gesture::Continuing ) + { + if( gesture.displacement.x < 0) + { + mIndex = (mIndex + 1)%NUM_IMAGES; + } + else + { + mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; + } + + mPanPosition = gesture.position; + mPanDisplacement = gesture.displacement; + GoToNextImage(); + } + } + + void CubeTransitionApp::GoToNextImage() + { + ResourceImage image = ResourceImage::New( IMAGES[ mIndex ] ); + mNextImage = ImageActor::New( image ); + mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION); + mNextImage.ApplyConstraint( mImageConstraint ); + mCurrentEffect.SetTargetImage(mNextImage); + if( image.GetLoadingState() == ResourceLoadingSucceeded ) + { + mIsImageLoading = false; + OnImageLoaded( image ); + } + else + { + mIsImageLoading = true; + image.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded ); + } + } + + void CubeTransitionApp::OnImageLoaded(ResourceImage image) + { + mIsImageLoading = false; + mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); + mParent.Remove(mCurrentImage); + mParent.Add(mNextImage); + mCurrentImage = mNextImage; + } + + bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) + { + if(mCurrentEffect == mCubeWaveEffect) + { + mCurrentEffect = mCubeCrossEffect; - mTitleActor.SetText( APPLICATION_TITLE_CROSS ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_CROSS ) ); + mEffectChangeButton.SetBackgroundImage(mImageCross); + + } + else if(mCurrentEffect == mCubeCrossEffect) + { + mCurrentEffect = mCubeFoldEffect; - mTitleActor.SetText( APPLICATION_TITLE_FOLD ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_FOLD ) ); + mEffectChangeButton.SetBackgroundImage(mImageFold); + } + else + { + mCurrentEffect = mCubeWaveEffect; - mTitleActor.SetText( APPLICATION_TITLE_WAVE ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_WAVE ) ); + mEffectChangeButton.SetBackgroundImage(mImageWave); + } - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); + + // Set the current image to cube transition effect + // only need to set at beginning or change from another effect + mCurrentEffect.SetCurrentImage(mCurrentImage); + return true; + } + + bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) + { + mSlideshow = !mSlideshow; + if( mSlideshow ) + { + mPanGestureDetector.Detach( mParent ); + mSlideshowButton.SetBackgroundImage( mIconSlideshowStop ); + mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f ); + mPanDisplacement = Vector2( -10.f, 0.f ); + mViewTimer.Start(); + } + else + { + mPanGestureDetector.Attach( mParent ); + mSlideshowButton.SetBackgroundImage( mIconSlideshowStart ); + mViewTimer.Stop(); + } + return true; + } + + void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor) + { + if( mSlideshow ) + { + mViewTimer.Start(); + } + } + + bool CubeTransitionApp::OnTimerTick() + { + if(mSlideshow) + { + mIndex = (mIndex + 1)%NUM_IMAGES; + GoToNextImage(); + } + + //return false to stop the timer + return false; + } + + void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + // Entry point for Linux & SLP applications + int main( int argc, char **argv ) + { + Application application = Application::New( &argc, &argv ); + CubeTransitionApp test( application ); + application.MainLoop(); + + return 0; + } diff --cc examples/dissolve-effect/dissolve-effect-example.cpp index 00000000,888a2547..8abfc674 mode 000000,100644..100644 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@@ -1,0 -1,421 +1,414 @@@ + /* + * 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. + * + */ + + // EXTERNAL INCLUDES + #include + + // INTERNAL INCLUDES + #include "shared/view.h" + + #include + #include + + using namespace Dali; + + // LOCAL STUFF + namespace + { + + const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + const char * const APPLICATION_TITLE_HIGHP( "Dissolve Effect(highp)" ); + const char * const APPLICATION_TITLE_MEDIUMP( "Dissolve Effect(mediump)" ); + const char * const EFFECT_HIGHP_IMAGE( DALI_IMAGE_DIR "icon-highp.png" ); + const char * const EFFECT_MEDIUMP_IMAGE( DALI_IMAGE_DIR "icon-mediump.png" ); + const char * const PLAY_ICON( DALI_IMAGE_DIR "icon-play.png" ); + const char * const STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" ); + + const char* IMAGES[] = + { + DALI_IMAGE_DIR "gallery-large-1.jpg", + DALI_IMAGE_DIR "gallery-large-2.jpg", + DALI_IMAGE_DIR "gallery-large-3.jpg", + DALI_IMAGE_DIR "gallery-large-4.jpg", + DALI_IMAGE_DIR "gallery-large-5.jpg", + DALI_IMAGE_DIR "gallery-large-6.jpg", + DALI_IMAGE_DIR "gallery-large-7.jpg", + DALI_IMAGE_DIR "gallery-large-8.jpg", + DALI_IMAGE_DIR "gallery-large-9.jpg", + DALI_IMAGE_DIR "gallery-large-10.jpg", + DALI_IMAGE_DIR "gallery-large-11.jpg", + DALI_IMAGE_DIR "gallery-large-12.jpg", + DALI_IMAGE_DIR "gallery-large-13.jpg", + DALI_IMAGE_DIR "gallery-large-14.jpg", + DALI_IMAGE_DIR "gallery-large-15.jpg", + DALI_IMAGE_DIR "gallery-large-16.jpg", + DALI_IMAGE_DIR "gallery-large-17.jpg", + DALI_IMAGE_DIR "gallery-large-18.jpg", + DALI_IMAGE_DIR "gallery-large-19.jpg", + DALI_IMAGE_DIR "gallery-large-20.jpg", + DALI_IMAGE_DIR "gallery-large-21.jpg", + }; + + const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) ); + + // The duration of the current image staying on screen when slideshow is on + const int VIEWINGTIME = 2000; // 2 seconds + + const float TRANSITION_DURATION = 2.5f; //2.5 second + + const float INITIAL_DEPTH = -10.0f; + } // namespace + + class DissolveEffectApp : public ConnectionTracker + { + public: + + /** + * Constructor + * @param application class, stored as reference + */ + DissolveEffectApp( Application& application ); + + ~DissolveEffectApp(); + + private: + + /** + * This method gets called once the main loop of application is up and running + */ + void OnInit( Application& application ); + /** + * PanGesture callback. This method gets called when the pan gesture is detected. + * @param[in] actor The actor receiving the pan gesture. + * @param[in] gesture The detected pan gesture. + */ + void OnPanGesture( Actor actor, const PanGesture& gesture ); + + /** + * Set up the animations for transition + * @param[in] position The point ( locates within rectange {(0,0),(0,1),(1,0),(1,1)} ) passing through the central line of the dissolve effect + * @param[in] displacement The direction of the central line of the dissolve effect + */ + void StartTransition(Vector2 position, Vector2 displacement); + /** + * Callback function of effect-switch button + * Change the precision of the effect shader when the effect button is clicked + * @param[in] button The handle of the clicked button + */ + bool OnEffectButtonClicked( Toolkit::Button button ); + /** + * Callback function of slideshow button + * Start or stop the automatical image display when the slideshow button is clicked + * @param[in] button The handle of the clicked button + */ + bool OnSildeshowButtonClicked( Toolkit::Button button ); + /** + * Callback function of cube transition completed signal + * @param[in] effect The cube effect used for the transition + * @param[in] imageActor The target imageActor of the completed transition + */ + void OnTransitionCompleted(Animation& source); + /** + * Callback function of timer tick + * The timer is used to count the image display duration after cube transition in slideshow, + */ + bool OnTimerTick(); + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event); + + private: + Application& mApplication; + Toolkit::View mView; + Toolkit::ToolBar mToolBar; + Layer mContent; - Toolkit::TextView mTitleActor; + Actor mParent; + + ImageActor mCurrentImage; + ImageActor mNextImage; + unsigned int mIndex; + Constraint mSizeConstraint; + + Toolkit::DissolveEffect mCurrentImageEffect; + Toolkit::DissolveEffect mNextImageEffect; + bool mUseHighPrecision; + Animation mAnimation; + + PanGestureDetector mPanGestureDetector; + bool mIsTransiting; + + bool mSlideshow; + Timer mViewTimer; + bool mTimerReady; + unsigned int mCentralLineIndex; + + Image mIconPlay; + Image mIconStop; + Toolkit::PushButton mPlayStopButton; + + Image mIconHighP; + Image mIconMediumP; + Toolkit::PushButton mEffectChangeButton; + }; + + DissolveEffectApp::DissolveEffectApp( Application& application ) + : mApplication( application ), + mIndex( 0 ), + mUseHighPrecision(true), + mIsTransiting( false ), + mSlideshow( false ), + mTimerReady( false ), + mCentralLineIndex( 0 ) + { + mApplication.InitSignal().Connect( this, &DissolveEffectApp::OnInit ); + } + + DissolveEffectApp::~DissolveEffectApp() + { + //Nothing to do + } + + void DissolveEffectApp::OnInit( Application& application ) + { + Stage::GetCurrent().KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent); + + // Creates a default view with a default tool bar, the view is added to the stage. + mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" ); + + // Add an effect-changing button on the right of the tool bar. + mIconHighP = ResourceImage::New( EFFECT_HIGHP_IMAGE ); + mIconMediumP = ResourceImage::New( EFFECT_MEDIUMP_IMAGE ); + mEffectChangeButton = Toolkit::PushButton::New(); + mEffectChangeButton.SetBackgroundImage(mIconHighP); + mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked ); + mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Add title to the tool bar. - mTitleActor = Toolkit::TextView::New(); - mTitleActor.SetText( APPLICATION_TITLE_HIGHP ); - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); ++ // TODO + + // Add an slide-show button on the right of the title + mIconPlay = ResourceImage::New( PLAY_ICON ); + mIconStop = ResourceImage::New( STOP_ICON ); + mPlayStopButton = Toolkit::PushButton::New(); + mPlayStopButton.SetBackgroundImage( mIconPlay ); + mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked ); + mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + + // use pan gesture to detect the cursor or finger movement + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); + + // create the dissolve effect object + mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); + mNextImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); + + mViewTimer = Timer::New( VIEWINGTIME ); + mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); + mTimerReady = true; + + // Set size to stage size to avoid seeing a black border on transition + mParent = Actor::New(); + mParent.SetSize( Stage::GetCurrent().GetSize() ); + mParent.SetPositionInheritanceMode( USE_PARENT_POSITION ); + mContent.Add( mParent ); + + mSizeConstraint= Constraint::New( Actor::Property::Scale, LocalSource( Actor::Property::Size ), ParentSource( Actor::Property::Size ), ScaleToFitKeepAspectRatioConstraint() ); + + // show the first image + mCurrentImage = ImageActor::New( ResourceImage::New( IMAGES[mIndex] ) ); + mCurrentImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); + mCurrentImage.ApplyConstraint( mSizeConstraint ); + mParent.Add( mCurrentImage ); + + mPanGestureDetector.Attach( mCurrentImage ); + } + + // signal handler, called when the pan gesture is detected + void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) + { + // does not response when the animation has not finished + if( mIsTransiting || mSlideshow ) + { + return; + } + + if( gesture.state == Gesture::Continuing ) + { + if( gesture.displacement.x < 0) + { + mIndex = (mIndex + 1)%NUM_IMAGES; + } + else + { + mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; + } + + Image image = ResourceImage::New( IMAGES[ mIndex ] ); + mNextImage = ImageActor::New( image ); + mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); + mNextImage.ApplyConstraint( mSizeConstraint ); + mNextImage.SetZ(INITIAL_DEPTH); + mParent.Add( mNextImage ); + Vector2 size = Vector2( mCurrentImage.GetCurrentSize() ); + StartTransition( gesture.position / size, gesture.displacement * Vector2(1.0, size.x/size.y)); + } + } + + void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) + { + mAnimation = Animation::New(TRANSITION_DURATION); + + mCurrentImageEffect.SetCentralLine(position,displacement); + mCurrentImageEffect.SetDistortion(0.0f); + mCurrentImage.SetShaderEffect(mCurrentImageEffect); + mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunctions::Linear ); + + mNextImage.SetOpacity(0.0f); + mAnimation.OpacityTo( mNextImage, 1.0, AlphaFunctions::Linear ); + + if(mUseHighPrecision) + { + mNextImageEffect.SetCentralLine(position,-displacement); + mNextImageEffect.SetDistortion(1.0f); + mNextImage.SetShaderEffect(mNextImageEffect); + mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunctions::Linear ); + } + else + { + mAnimation.MoveTo(mNextImage, Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Linear); + } + + mAnimation.FinishedSignal().Connect( this, &DissolveEffectApp::OnTransitionCompleted ); + mAnimation.Play(); + mIsTransiting = true; + } + + void DissolveEffectApp::OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) + { + mUseHighPrecision = !mUseHighPrecision; + mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision); + if(mUseHighPrecision) + { - mTitleActor.SetText( APPLICATION_TITLE_HIGHP ); + mEffectChangeButton.SetBackgroundImage(mIconHighP); + } + else + { - mTitleActor.SetText( APPLICATION_TITLE_MEDIUMP ); + mEffectChangeButton.SetBackgroundImage(mIconMediumP); + } - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); + + return true; + } + + bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button ) + { + mSlideshow = !mSlideshow; + if( mSlideshow ) + { + mPlayStopButton.SetBackgroundImage( mIconStop ); + mPanGestureDetector.Detach( mParent ); + mViewTimer.Start(); + mTimerReady = false; + } + else + { + mPlayStopButton.SetBackgroundImage( mIconPlay ); + mTimerReady = true; + mPanGestureDetector.Attach( mParent ); + } + return true; + } + + void DissolveEffectApp::OnTransitionCompleted( Animation& source ) + { + mCurrentImage.RemoveShaderEffect(); + mNextImage.RemoveShaderEffect(); + mParent.Remove( mCurrentImage ); + mPanGestureDetector.Detach( mCurrentImage ); + mCurrentImage = mNextImage; + mPanGestureDetector.Attach( mCurrentImage ); + mIsTransiting = false; + + if( mSlideshow) + { + mViewTimer.Start(); + mTimerReady = false; + } + } + + bool DissolveEffectApp::OnTimerTick() + { + mTimerReady = true; + if(mSlideshow) + { + mIndex = (mIndex + 1)%NUM_IMAGES; + Image image = ResourceImage::New( IMAGES[ mIndex ] ); + mNextImage = ImageActor::New( image ); + mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); + mNextImage.ApplyConstraint( mSizeConstraint ); + mNextImage.SetZ(INITIAL_DEPTH); + mParent.Add( mNextImage ); + switch( mCentralLineIndex%4 ) + { + case 0: + { + StartTransition(Vector2(1.0f,0.5f), Vector2(-1.0f, 0.0f)); + break; + } + case 1: + { + StartTransition(Vector2(0.5f,0.0f), Vector2(0.0f, 1.0f)); + break; + } + case 2: + { + StartTransition(Vector2(0.0f,0.5f), Vector2(1.0f, 0.0f)); + break; + } + default: + { + StartTransition(Vector2(0.5f,1.0f), Vector2(0.0f, -1.0f)); + break; + } + + } + mCentralLineIndex++; + } + return false; //return false to stop the timer + } + + // Entry point for Linux & SLP applications + int main( int argc, char **argv ) + { + Application application = Application::New( &argc, &argv ); + DissolveEffectApp test( application ); + application.MainLoop(); + + return 0; + } diff --cc examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index 00000000,437194cf..1d82b001 mode 000000,100644..100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@@ -1,0 -1,597 +1,586 @@@ + /* + * 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. + * + */ + + /** + * @file image-scaling-irregular-grid-example.cpp + * @brief Demonstrates how to use image scaling modes when loading images. + * + * If an image is going to be drawn on-screen at a lower resolution than it is + * stored at on-disk, the scaling feature of the image loader can be used to + * reduce the image to save memory, improve performance, and potentially display + * a better small version of the image than if the default size were loaded. + * + * The functions CreateImage and CreateImageActor below show how to build an + * image using a scaling mode to have %Dali resize it during loading. + * + * This demo defaults to the ScaleToFill mode of ImageAttributes which makes + * sure that every pixel in the loaded image is filled with a source colour + * from the image's central region while losing the minimum number of pixels + * from its periphery. + * It is the best option for producing thumbnails of input images that have + * diverse aspect ratios. + * + * The other four scaling modes of dali can be cycled-through for the whole + * grid using the button in the top-right of the toolbar. + * A single image can be cycled by clicking the image directly. + * + * @see CreateImage CreateImageActor + */ + + // EXTERNAL INCLUDES + #include + #include + #include + #include + + // INTERNAL INCLUDES + #include "grid-flags.h" + #include "shared/view.h" + + using namespace Dali; + using namespace Dali::Toolkit; + using namespace Dali::Demo; + + namespace + { + + /** Controls the output of application logging. */ + //#define DEBUG_PRINT_DIAGNOSTICS; + + const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); + const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + const char* APPLICATION_TITLE( "Image Scaling Modes" ); + const char* TOGGLE_SCALING_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); + + /** The width of the grid in whole grid cells. */ + const unsigned GRID_WIDTH = 9; + /** Limit the grid to be no higher than this in units of a cell. */ + const unsigned GRID_MAX_HEIGHT = 600; + + /** The space between the edge of a grid cell and the image embedded within it. */ + const unsigned GRID_CELL_PADDING = 4; + + /** The aspect ratio of cells in the image grid. */ + const float CELL_ASPECT_RATIO = 1.33333333333333333333f; + + const ImageAttributes::ScalingMode DEFAULT_SCALING_MODE = ImageAttributes::ScaleToFill; + + /** The number of times to spin an image on touching, each spin taking a second.*/ + const float SPIN_DURATION = 1.0f; + + /** The target image sizes in grid cells. */ + const Vector2 IMAGE_SIZES[] = { + Vector2( 1, 1 ), + Vector2( 2, 1 ), + Vector2( 3, 1 ), + Vector2( 1, 2 ), + Vector2( 1, 3 ), + Vector2( 2, 3 ), + Vector2( 3, 2 ), + // Large, tall configuration: + Vector2( GRID_WIDTH / 2, GRID_WIDTH + GRID_WIDTH / 2 ), + // Large, square-ish images to show shrink-to-fit well with wide and tall images: + Vector2( GRID_WIDTH / 2, GRID_WIDTH / 2.0f * CELL_ASPECT_RATIO + 0.5f ), + Vector2( GRID_WIDTH - 2, (GRID_WIDTH - 2) * CELL_ASPECT_RATIO + 0.5f ), + }; + const unsigned NUM_IMAGE_SIZES = sizeof(IMAGE_SIZES) / sizeof(IMAGE_SIZES[0]); + + /** Images to load into the grid. These are mostly large and non-square to + * show the scaling. */ + const char* IMAGE_PATHS[] = { + + DALI_IMAGE_DIR "dali-logo.png", + DALI_IMAGE_DIR "com.samsung.dali-demo.ico", + DALI_IMAGE_DIR "square_primitive_shapes.bmp", + DALI_IMAGE_DIR "gallery-large-14.wbmp", + + // Images that show aspect ratio changes clearly in primitive shapes: + + DALI_IMAGE_DIR "portrait_screen_primitive_shapes.gif", + DALI_IMAGE_DIR "landscape_screen_primitive_shapes.gif", + + // Images from other demos that are tall, wide or just large: + + DALI_IMAGE_DIR "gallery-large-1.jpg", + DALI_IMAGE_DIR "gallery-large-2.jpg", + DALI_IMAGE_DIR "gallery-large-3.jpg", + DALI_IMAGE_DIR "gallery-large-4.jpg", + DALI_IMAGE_DIR "gallery-large-5.jpg", + DALI_IMAGE_DIR "gallery-large-6.jpg", + DALI_IMAGE_DIR "gallery-large-7.jpg", + DALI_IMAGE_DIR "gallery-large-8.jpg", + DALI_IMAGE_DIR "gallery-large-9.jpg", + DALI_IMAGE_DIR "gallery-large-10.jpg", + DALI_IMAGE_DIR "gallery-large-11.jpg", + DALI_IMAGE_DIR "gallery-large-12.jpg", + DALI_IMAGE_DIR "gallery-large-13.jpg", + DALI_IMAGE_DIR "gallery-large-14.jpg", + DALI_IMAGE_DIR "gallery-large-15.jpg", + DALI_IMAGE_DIR "gallery-large-16.jpg", + DALI_IMAGE_DIR "gallery-large-17.jpg", + DALI_IMAGE_DIR "gallery-large-18.jpg", + DALI_IMAGE_DIR "gallery-large-19.jpg", + DALI_IMAGE_DIR "gallery-large-20.jpg", + DALI_IMAGE_DIR "gallery-large-21.jpg", + + DALI_IMAGE_DIR "background-1.jpg", + DALI_IMAGE_DIR "background-2.jpg", + DALI_IMAGE_DIR "background-3.jpg", + DALI_IMAGE_DIR "background-4.jpg", + DALI_IMAGE_DIR "background-5.jpg", + DALI_IMAGE_DIR "background-blocks.jpg", + DALI_IMAGE_DIR "background-magnifier.jpg", + + DALI_IMAGE_DIR "background-1.jpg", + DALI_IMAGE_DIR "background-2.jpg", + DALI_IMAGE_DIR "background-3.jpg", + DALI_IMAGE_DIR "background-4.jpg", + DALI_IMAGE_DIR "background-5.jpg", + DALI_IMAGE_DIR "background-blocks.jpg", + DALI_IMAGE_DIR "background-magnifier.jpg", + + DALI_IMAGE_DIR "book-landscape-cover-back.jpg", + DALI_IMAGE_DIR "book-landscape-cover.jpg", + DALI_IMAGE_DIR "book-landscape-p1.jpg", + DALI_IMAGE_DIR "book-landscape-p2.jpg", + + DALI_IMAGE_DIR "book-portrait-cover.jpg", + DALI_IMAGE_DIR "book-portrait-p1.jpg", + DALI_IMAGE_DIR "book-portrait-p2.jpg", + NULL + }; + const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; + + + /** + * Creates an Image + * + * @param[in] filename The path of the image. + * @param[in] width The width of the image in pixels. + * @param[in] height The height of the image in pixels. + * @param[in] scalingMode The mode to use when scaling the image to fit the desired dimensions. + */ + Image CreateImage(const std::string& filename, unsigned int width, unsigned int height, ImageAttributes::ScalingMode scalingMode ) + { + #ifdef DEBUG_PRINT_DIAGNOSTICS + fprintf( stderr, "CreateImage(%s, %u, %u, scalingMode=%u)\n", filename.c_str(), width, height, unsigned( scalingMode ) ); + #endif + ImageAttributes attributes; + + attributes.SetSize( width, height ); + attributes.SetScalingMode( scalingMode ); + Image image = ResourceImage::New( filename, attributes ); + return image; + } + + /** + * Creates an ImageActor + * + * @param[in] filename The path of the image. + * @param[in] width The width of the image in pixels. + * @param[in] height The height of the image in pixels. + * @param[in] scalingMode The mode to use when scaling the image to fit the desired dimensions. + */ + ImageActor CreateImageActor(const std::string& filename, unsigned int width, unsigned int height, ImageAttributes::ScalingMode scalingMode ) + { + Image img = CreateImage( filename, width, height, scalingMode ); + ImageActor actor = ImageActor::New( img ); + actor.SetName( filename ); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetAnchorPoint(AnchorPoint::CENTER); + + return actor; + } + + /** Cycle the scaling mode options. */ + ImageAttributes::ScalingMode NextMode( const ImageAttributes::ScalingMode oldMode ) + { + ImageAttributes::ScalingMode newMode = ImageAttributes::ShrinkToFit; + switch ( oldMode ) + { + case ImageAttributes::ShrinkToFit: + newMode = ImageAttributes::ScaleToFill; + break; + case ImageAttributes::ScaleToFill: + newMode = ImageAttributes::FitWidth; + break; + case ImageAttributes::FitWidth: + newMode = ImageAttributes::FitHeight; + break; + case ImageAttributes::FitHeight: + newMode = ImageAttributes::ShrinkToFit; + break; + } + return newMode; + } + + /** + * Bundle an image path with the rectangle to pack it into. + * */ + struct ImageConfiguration + { + ImageConfiguration( const char * const path, const Vector2 dimensions ) : + path( path ), + dimensions( dimensions ) + {} + const char * path; + Vector2 dimensions; + }; + + /** + * Post-layout image data. + */ + struct PositionedImage + { + PositionedImage(ImageConfiguration& configuration, unsigned cellX, unsigned cellY, Vector2 imageGridDims) : + configuration( configuration ), + cellX( cellX ), + cellY( cellY ), + imageGridDims( imageGridDims ) + {} + + ImageConfiguration configuration; + unsigned cellX; + unsigned cellY; + Vector2 imageGridDims; + }; + + } + + /** + * @brief The main class of the demo. + */ + class ImageScalingIrregularGridController : public ConnectionTracker + { + public: + + ImageScalingIrregularGridController( Application& application ) + : mApplication( application ), + mScrolling( false ) + { + std::cout << "ImageScalingScaleToFillController::ImageScalingScaleToFillController" << std::endl; + + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &ImageScalingIrregularGridController::Create ); + } + + ~ImageScalingIrregularGridController() + { + // Nothing to do here. + } + + /** + * One-time setup in response to Application InitSignal. + */ + void Create( Application& application ) + { + std::cout << "ImageScalingScaleToFillController::Create" << std::endl; + + // Get a handle to the stage: + Stage stage = Stage::GetCurrent(); + + // Connect to input event signals: + stage.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent); + + // Hide the indicator bar + mApplication.GetWindow().ShowIndicator(Dali::Window::INVISIBLE); + + // Create a default view with a default tool bar: + mContentLayer = DemoHelper::CreateView( mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + "" ); + + // Create an image scaling toggle button. (right of toolbar) + Image toggleScalingImage = ResourceImage::New( TOGGLE_SCALING_IMAGE ); + Toolkit::PushButton toggleScalingButton = Toolkit::PushButton::New(); + toggleScalingButton.SetBackgroundImage( toggleScalingImage ); + toggleScalingButton.ClickedSignal().Connect( this, &ImageScalingIrregularGridController::OnToggleScalingTouched ); + mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + SetTitle( APPLICATION_TITLE ); + + // Build the main content of the widow: + PopulateContentLayer( DEFAULT_SCALING_MODE ); + } + + /** + * Build the main part of the application's view. + */ + void PopulateContentLayer( const ImageAttributes::ScalingMode scalingMode ) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + float fieldHeight; + Actor imageField = BuildImageField( stageSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, scalingMode, fieldHeight ); + + mScrollView = ScrollView::New(); + + mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted ); + mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted ); + + mScrollView.EnableScrollComponent( Scrollable::VerticalScrollBar ); + mScrollView.EnableScrollComponent( Scrollable::HorizontalScrollBar ); + + mScrollView.SetAnchorPoint(AnchorPoint::CENTER); + mScrollView.SetParentOrigin(ParentOrigin::CENTER); + + mScrollView.SetSize( stageSize );//Vector2( stageSize.width, fieldHeight ) );//stageSize ); + mScrollView.SetAxisAutoLock( true ); + mScrollView.SetAxisAutoLockGradient( 1.0f ); + + // Restrict scrolling to mostly vertical only, but with some horizontal wiggle-room: + + RulerPtr rulerX = new FixedRuler( stageSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler. + rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field. + mScrollView.SetRulerX ( rulerX ); + + RulerPtr rulerY = new DefaultRuler(); //stageSize.height ); //< Snap in multiples of a screen / stage height + rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) ); + mScrollView.SetRulerY ( rulerY ); + + mContentLayer.Add( mScrollView ); + mScrollView.Add( imageField ); + mGridActor = imageField; + } + + /** + * Build a field of images scaled into a variety of shapes from very wide, + * through square, to very tall. The images are direct children of the Dali::Actor + * returned. + **/ + Actor BuildImageField( const float fieldWidth, + const unsigned gridWidth, + const unsigned maxGridHeight, + ImageAttributes::ScalingMode scalingMode, + float & outFieldHeight ) + { + // Generate the list of image configurations to be fitted into the field: + + std::vector configurations; + configurations.reserve( NUM_IMAGE_PATHS * NUM_IMAGE_SIZES ); + for( unsigned imageIndex = 0; imageIndex < NUM_IMAGE_PATHS; ++imageIndex ) + { + for( unsigned dimensionsIndex = 0; dimensionsIndex < NUM_IMAGE_SIZES; ++ dimensionsIndex ) + { + configurations.push_back( ImageConfiguration( IMAGE_PATHS[imageIndex], IMAGE_SIZES[dimensionsIndex] ) ); + } + } + // Stir-up the list to get some nice irregularity in the generated field: + std::random_shuffle( configurations.begin(), configurations.end() ); + std::random_shuffle( configurations.begin(), configurations.end() ); + + // Place the images in the grid: + + std::vector::iterator config, end; + GridFlags grid( gridWidth, maxGridHeight ); + std::vector placedImages; + + for( config = configurations.begin(), end = configurations.end(); config != end; ++config ) + { + unsigned cellX, cellY; + Vector2 imageGridDims; + + // Allocate a region of the grid for the image: + bool allocated = grid.AllocateRegion( config->dimensions, cellX, cellY, imageGridDims ); + if( !allocated ) + { + #ifdef DEBUG_PRINT_DIAGNOSTICS + fprintf( stderr, "Failed to allocate image in grid with dims (%f, %f) and path: %s.\n", config->dimensions.x, config->dimensions.y, config->path ); + #endif + continue; + } + + placedImages.push_back( PositionedImage( *config, cellX, cellY, imageGridDims ) ); + } + DALI_ASSERT_DEBUG( grid.DebugCheckGridValid() && "Cells were set more than once, indicating erroneous overlap in placing images on the grid." ); + const unsigned actualGridHeight = grid.GetHighestUsedRow() + 1; + + // Take the images images in the grid and turn their logical locations into + // coordinates in a frame defined by a parent actor: + + Actor gridActor = Actor::New(); + gridActor.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + gridActor.SetParentOrigin( ParentOrigin::CENTER ); + gridActor.SetAnchorPoint( AnchorPoint::CENTER ); + + // Work out the constants of the grid and cell dimensions and positions: + const float cellWidth = fieldWidth / gridWidth; + const float cellHeight = cellWidth / CELL_ASPECT_RATIO; + const Vector2 cellSize = Vector2( cellWidth, cellHeight ); + outFieldHeight = actualGridHeight * cellHeight; + const Vector2 gridOrigin = Vector2( -fieldWidth * 0.5f, -outFieldHeight * 0.5 ); + + // Build the image actors in their right locations in their parent's frame: + for( std::vector::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i ) + { + const PositionedImage& imageSource = *i; + const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2( GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2 ); + const Vector2 imageRegionCorner = gridOrigin + cellSize * Vector2( imageSource.cellX, imageSource.cellY ); + const Vector2 imagePosition = imageRegionCorner + Vector2( GRID_CELL_PADDING , GRID_CELL_PADDING ) + imageSize * 0.5f; + + ImageActor image = CreateImageActor( imageSource.configuration.path, imageSize.x, imageSize.y, scalingMode ); + image.SetPosition( Vector3( imagePosition.x, imagePosition.y, 0 ) ); + image.SetSize( imageSize ); + image.TouchedSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage ); + mScalingModes[image.GetId()] = scalingMode; + mSizes[image.GetId()] = imageSize; + + gridActor.Add( image ); + } + + return gridActor; + } + + /** + * Upon Touching an image (Release), change its scaling mode and make it spin, provided we're not scrolling. + * @param[in] actor The actor touched + * @param[in] event The TouchEvent. + */ + bool OnTouchImage( Actor actor, const TouchEvent& event ) + { + if( (event.points.size() > 0) && (!mScrolling) ) + { + TouchPoint point = event.points[0]; + if(point.state == TouchPoint::Up) + { + // Spin the image a few times: + Animation animation = Animation::New(SPIN_DURATION); + animation.RotateBy( actor, Degree(360.0f * SPIN_DURATION), Vector3::XAXIS, AlphaFunctions::EaseOut); + animation.Play(); + + // Change the scaling mode: + const unsigned id = actor.GetId(); + ImageAttributes::ScalingMode newMode = NextMode( mScalingModes[id] ); + const Vector2 imageSize = mSizes[actor.GetId()]; + + ImageActor imageActor = ImageActor::DownCast( actor ); + Image oldImage = imageActor.GetImage(); + Image newImage = CreateImage( ResourceImage::DownCast(oldImage).GetUrl(), imageSize.width + 0.5f, imageSize.height + 0.5f, newMode ); + imageActor.SetImage( newImage ); + mScalingModes[id] = newMode; + } + } + return false; + } + + /** + * Main key event handler. + * Quit on escape key. + */ + void OnKeyEvent(const KeyEvent& event) + { + if( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) + || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + + /** + * Signal handler, called when the 'Scaling' button has been touched. + * + * @param[in] button The button that was pressed. + */ + bool OnToggleScalingTouched( Button button ) + { + const unsigned numChildren = mGridActor.GetChildCount(); + + for( unsigned i = 0; i < numChildren; ++i ) + { + ImageActor gridImageActor = ImageActor::DownCast( mGridActor.GetChildAt( i ) ); + if( gridImageActor ) + { + // Cycle the scaling mode options: + const Vector2 imageSize = mSizes[gridImageActor.GetId()]; + ImageAttributes::ScalingMode newMode = NextMode( mScalingModes[gridImageActor.GetId()] ); + Image oldImage = gridImageActor.GetImage(); + Image newImage = CreateImage(ResourceImage::DownCast(oldImage).GetUrl(), imageSize.width, imageSize.height, newMode ); + gridImageActor.SetImage( newImage ); + + mScalingModes[gridImageActor.GetId()] = newMode; + + SetTitle( std::string( newMode == ImageAttributes::ShrinkToFit ? "ShrinkToFit" : newMode == ImageAttributes::ScaleToFill ? "ScaleToFill" : newMode == ImageAttributes::FitWidth ? "FitWidth" : "FitHeight" ) ); + } + } + return true; + } + + /** + * Sets/Updates the title of the View + * @param[in] title The new title for the view. + */ + void SetTitle(const std::string& title) + { - if(!mTitleActor) - { - mTitleActor = TextView::New(); - // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); - } - - Font font = Font::New(); - mTitleActor.SetText( title ); - mTitleActor.SetSize( font.MeasureText( title ) ); - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); ++ // TODO + } + + /** + * When scroll starts (i.e. user starts to drag scrollview), + * note this state (mScrolling = true) + * @param[in] position Current Scroll Position + */ + void OnScrollStarted( const Vector3& position ) + { + mScrolling = true; + } + + /** + * When scroll starts (i.e. user stops dragging scrollview, and scrollview has snapped to destination), + * note this state (mScrolling = false). + * @param[in] position Current Scroll Position + */ + void OnScrollCompleted( const Vector3& position ) + { + mScrolling = false; + } + + private: + Application& mApplication; + + Layer mContentLayer; ///< The content layer (contains non gui chrome actors) + Toolkit::View mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - TextView mTitleActor; ///< The Toolbar's Title. + Actor mGridActor; ///< The container for the grid of images + ScrollView mScrollView; ///< ScrollView UI Component + bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) + std::map mScalingModes; ///< Stores the current scaling mode of each image, keyed by image actor id. + std::map mSizes; ///< Stores the current size of each image, keyed by image actor id. + }; + + void RunTest( Application& application ) + { + ImageScalingIrregularGridController test( application ); + + application.MainLoop(); + } + + /** Entry point for Linux & Tizen applications */ + int main( int argc, char **argv ) + { + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; + } diff --cc examples/item-view/item-view-example.cpp index 1be6a055,f835fbc4..2f8f242b --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@@ -1066,7 -1123,8 +1066,7 @@@ private Toolkit::PushButton mReplaceButton; unsigned int mAlphaFuncIndex; - BitmapImage mWhiteImage; - TextView mAlphaFunctionText; + BufferImage mWhiteImage; }; void RunTest(Application& app) diff --cc examples/motion-blur/motion-blur-example.cpp index 00000000,82f7ab58..f0cc48cb mode 000000,100644..100644 --- a/examples/motion-blur/motion-blur-example.cpp +++ b/examples/motion-blur/motion-blur-example.cpp @@@ -1,0 -1,549 +1,548 @@@ + /* + * 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 + #include + + #include "shared/view.h" + #include + #include + + using namespace Dali; + using namespace Dali::Toolkit; + + + + namespace // unnamed namespace + { + + //////////////////////////////////////////////////// + // + // Demo setup parameters + // + + //#define MULTIPLE_MOTION_BLURRED_ACTORS + #ifndef MULTIPLE_MOTION_BLURRED_ACTORS + + const float MOTION_BLUR_ACTOR_WIDTH = 256; // actor size on screen + const float MOTION_BLUR_ACTOR_HEIGHT = 256; // "" + + #else //#ifndef MULTIPLE_MOTION_BLURRED_ACTORS + + const float MOTION_BLUR_ACTOR_WIDTH = 150; // actor size on screen + const float MOTION_BLUR_ACTOR_HEIGHT = 112; // "" + + #endif //#ifndef MULTIPLE_MOTION_BLURRED_ACTORS + + + const unsigned int MOTION_BLUR_NUM_SAMPLES = 8; + + const int MOTION_BLUR_NUM_ACTOR_IMAGES = 5; + const char* MOTION_BLUR_ACTOR_IMAGE1( DALI_IMAGE_DIR "image-with-border-1.jpg" ); + const char* MOTION_BLUR_ACTOR_IMAGE2( DALI_IMAGE_DIR "image-with-border-2.jpg" ); + const char* MOTION_BLUR_ACTOR_IMAGE3( DALI_IMAGE_DIR "image-with-border-3.jpg" ); + const char* MOTION_BLUR_ACTOR_IMAGE4( DALI_IMAGE_DIR "image-with-border-4.jpg" ); + const char* MOTION_BLUR_ACTOR_IMAGE5( DALI_IMAGE_DIR "image-with-border-1.jpg" ); + + const char* MOTION_BLUR_ACTOR_IMAGES[] = { + MOTION_BLUR_ACTOR_IMAGE1, + MOTION_BLUR_ACTOR_IMAGE2, + MOTION_BLUR_ACTOR_IMAGE3, + MOTION_BLUR_ACTOR_IMAGE4, + MOTION_BLUR_ACTOR_IMAGE5, + }; + + const int NUM_ACTOR_ANIMATIONS = 4; + const int NUM_CAMERA_ANIMATIONS = 2; + + + const char* BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "background-default.png"; + + const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + const char* LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); + const char* APPLICATION_TITLE( "Motion Blur" ); + const char* EFFECTS_OFF_ICON( DALI_IMAGE_DIR "icon-effects-off.png" ); + const char* EFFECTS_ON_ICON( DALI_IMAGE_DIR "icon-effects-on.png" ); + + const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons + + const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); + const Vector3 BUTTON_TITLE_LABEL_TAP_HERE_SIZE_CONSTRAINT( 0.55f, 0.06f, 1.0f ); + const Vector3 BUTTON_TITLE_LABEL_INSTRUCTIONS_POPUP_SIZE_CONSTRAINT( 1.0f, 1.0f, 1.0f ); + + // move this button down a bit so it is visible on target and not covered up by toolbar + const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; + + const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. + } // unnamed namespace + + + + + // + class MotionBlurExampleApp : public ConnectionTracker + { + public: + + /** + * DeviceOrientation describes the four different + * orientations the device can be in based on accelerometer reports. + */ + enum DeviceOrientation + { + PORTRAIT = 0, + LANDSCAPE = 90, + PORTRAIT_INVERSE = 180, + LANDSCAPE_INVERSE = 270 + }; + + /** + * Constructor + * @param application class, stored as reference + */ + MotionBlurExampleApp(Application &app) + : mApplication(app), + mActorEffectsEnabled(false), + mCurrentActorAnimation(0), + mCurrentImage(0) + { + // Connect to the Application's Init signal + app.InitSignal().Connect(this, &MotionBlurExampleApp::OnInit); + } + + ~MotionBlurExampleApp() + { + // Nothing to do here; everything gets deleted automatically + } + + /** + * This method gets called once the main loop of application is up and running + */ + void OnInit(Application& app) + { + // The Init signal is received once (only) during the Application lifetime + + Stage::GetCurrent().KeyEventSignal().Connect(this, &MotionBlurExampleApp::OnKeyEvent); + + + // Creates a default view with a default tool bar. + // The view is added to the stage. + mContentLayer = DemoHelper::CreateView( mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE_PATH, + TOOLBAR_IMAGE, + APPLICATION_TITLE ); + + //Add an effects icon on the right of the title + mIconEffectsOff = ResourceImage::New( EFFECTS_OFF_ICON ); + mIconEffectsOn = ResourceImage::New( EFFECTS_ON_ICON ); + mActorEffectsButton = Toolkit::PushButton::New(); + mActorEffectsButton.SetBackgroundImage( mIconEffectsOff ); + mActorEffectsButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnEffectButtonClicked ); + mToolBar.AddControl( mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + + // Creates a mode button. + // Create a effect toggle button. (right of toolbar) + Image imageLayout = ResourceImage::New( LAYOUT_IMAGE ); + Toolkit::PushButton layoutButton = Toolkit::PushButton::New(); + layoutButton.SetBackgroundImage(imageLayout); + layoutButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnLayoutButtonClicked); + layoutButton.SetLeaveRequired( true ); + mToolBar.AddControl( layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Input + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mContentLayer ); + mTapGestureDetector.DetectedSignal().Connect( this, &MotionBlurExampleApp::OnTap ); + + Dali::Window winHandle = app.GetWindow(); + winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); + winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); + winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); + winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); + + // set initial orientation + app.GetOrientation().ChangedSignal().Connect( this, &MotionBlurExampleApp::OnOrientationChanged ); + unsigned int degrees = app.GetOrientation().GetDegrees(); + Rotate( static_cast< DeviceOrientation >( degrees ) ); + + + /////////////////////////////////////////////////////// + // + // Motion blurred actor + // + + Image image = ResourceImage::New( MOTION_BLUR_ACTOR_IMAGE1 ); + mMotionBlurImageActor = ImageActor::New(image); + mMotionBlurImageActor.SetParentOrigin( ParentOrigin::CENTER ); + mMotionBlurImageActor.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); + + mContentLayer.Add( mMotionBlurImageActor ); + + // Create shader used for doing motion blur + mMotionBlurEffect = MotionBlurEffect::Apply(mMotionBlurImageActor); + + + #ifdef MULTIPLE_MOTION_BLURRED_ACTORS + + /////////////////////////////////////////////////////// + // + // Motion blurred actor 2 + // + + mMotionBlurImageActor2 = ImageActor::New(image); + mMotionBlurImageActor2.SetParentOrigin( ParentOrigin::CENTER ); + mMotionBlurImageActor2.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); + mMotionBlurImageActor2.SetPosition(MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f); + mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); + + // Create shader used for doing motion blur + mMotionBlurEffect2 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + + // set actor shader to the blur one + mMotionBlurImageActor2.SetShaderEffect( mMotionBlurEffect2 ); + + + /////////////////////////////////////////////////////// + // + // Motion blurred actor 3 + // + + mMotionBlurImageActor3 = ImageActor::New(image); + mMotionBlurImageActor3.SetParentOrigin( ParentOrigin::CENTER ); + mMotionBlurImageActor3.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); + mMotionBlurImageActor3.SetPosition(-MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f); + mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); + + // Create shader used for doing motion blur + mMotionBlurEffect3 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + + // set actor shader to the blur one + mMotionBlurImageActor3.SetShaderEffect( mMotionBlurEffect3 ); + + + /////////////////////////////////////////////////////// + // + // Motion blurred actor 4 + // + + mMotionBlurImageActor4 = ImageActor::New(image); + mMotionBlurImageActor4.SetParentOrigin( ParentOrigin::CENTER ); + mMotionBlurImageActor4.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); + mMotionBlurImageActor4.SetPosition(0.0f, MOTION_BLUR_ACTOR_HEIGHT * 1.1f); + mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); + + // Create shader used for doing motion blur + mMotionBlurEffect4 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + + // set actor shader to the blur one + mMotionBlurImageActor4.SetShaderEffect( mMotionBlurEffect4 ); + + + /////////////////////////////////////////////////////// + // + // Motion blurred actor 5 + // + + mMotionBlurImageActor5 = ImageActor::New(image); + mMotionBlurImageActor5.SetParentOrigin( ParentOrigin::CENTER ); + mMotionBlurImageActor5.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); + mMotionBlurImageActor5.SetPosition(0.0f, -MOTION_BLUR_ACTOR_HEIGHT * 1.1f); + mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); + + // Create shader used for doing motion blur + mMotionBlurEffect5 = MotionBlurEffect::New(MOTION_BLUR_NUM_SAMPLES); + + // set actor shader to the blur one + mMotionBlurImageActor5.SetShaderEffect( mMotionBlurEffect5 ); + #endif //#ifdef MULTIPLE_MOTION_BLURRED_ACTORS + } + + ////////////////////////////////////////////////////////////// + // + // Device Orientation Support + // + // + + void OnOrientationChanged( Orientation orientation ) + { + unsigned int degrees = orientation.GetDegrees(); + Rotate( static_cast< DeviceOrientation >( degrees ) ); + } + + void Rotate( DeviceOrientation orientation ) + { + // Resize the root actor + Vector2 stageSize = Stage::GetCurrent().GetSize(); + Vector2 targetSize = stageSize; + if( orientation == LANDSCAPE || + orientation == LANDSCAPE_INVERSE ) + { + targetSize = Vector2( stageSize.y, stageSize.x ); + } + + if( mOrientation != orientation ) + { + mOrientation = orientation; + + // check if actor is on stage + if( mView.GetParent() ) + { + // has parent so we expect it to be on stage, start animation + mRotateAnimation = Animation::New( ORIENTATION_DURATION ); + mRotateAnimation.RotateTo( mView, Degree( -orientation ), Vector3::ZAXIS, AlphaFunctions::EaseOut ); + mRotateAnimation.Resize( mView, targetSize.width, targetSize.height ); + mRotateAnimation.Play(); + } + else + { + // set the rotation to match the orientation + mView.SetRotation( Degree( -orientation ), Vector3::ZAXIS ); + mView.SetSize( targetSize ); + } + } + else + { + // for first time just set size + mView.SetSize( targetSize ); + } + } + + + ////////////////////////////////////////////////////////////// + // + // Actor Animation + // + // + + // move to point on screen that was tapped + void OnTap( Actor actor, const TapGesture& tapGesture ) + { + Vector3 destPos; + float originOffsetX, originOffsetY; + + // rotate offset (from top left origin to centre) into actor space + Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + actor.ScreenToLocal(originOffsetX, originOffsetY, stageSize.width * 0.5f, stageSize.height * 0.5f); + + // get dest point in local actor space + destPos.x = tapGesture.localPoint.x - originOffsetX; + destPos.y = tapGesture.localPoint.y - originOffsetY; + destPos.z = 0.0f; + + float animDuration = 0.5f; + mActorTapMovementAnimation = Animation::New( animDuration ); + if ( mMotionBlurImageActor ) + { + mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageActor, Actor::Property::Position), destPos, AlphaFunctions::EaseInOutSine, TimePeriod(animDuration) ); + } + mActorTapMovementAnimation.SetEndAction( Animation::Bake ); + mActorTapMovementAnimation.Play(); + + + // perform some spinning etc + if(mActorEffectsEnabled) + { + switch(mCurrentActorAnimation) + { + // spin around y + case 0: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // spin around z + case 1: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(720), Vector3::ZAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // spin around y and z + case 2: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(360), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.RotateBy(mMotionBlurImageActor, Degree(360), Vector3::ZAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // scale + case 3: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.ScaleBy(mMotionBlurImageActor, Vector3(2.0f, 2.0f, 2.0f), AlphaFunctions::Bounce, 0.0f, 1.0f); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + default: + break; + } + + mCurrentActorAnimation++; + if(NUM_ACTOR_ANIMATIONS == mCurrentActorAnimation) + { + mCurrentActorAnimation = 0; + } + } + } + + void ToggleActorEffects() + { + if(!mActorEffectsEnabled) + { + mActorEffectsEnabled = true; + mActorEffectsButton.SetBackgroundImage( mIconEffectsOn ); + } + else + { + mActorEffectsEnabled = false; + mActorEffectsButton.SetBackgroundImage( mIconEffectsOff ); + } + } + + ////////////////////////////////////////////////////////////// + // + // Input handlers + // + // + + bool OnLayoutButtonClicked( Toolkit::Button button ) + { + ChangeImage(); + return true; + } + + bool OnEffectButtonClicked( Toolkit::Button button ) + { + ToggleActorEffects(); + return true; + } + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + ////////////////////////////////////////////////////////////// + // + // Misc + // + // + + + void ChangeImage() + { + mCurrentImage++; + if(MOTION_BLUR_NUM_ACTOR_IMAGES == mCurrentImage) + { + mCurrentImage = 0; + } + + Image blurImage = ResourceImage::New( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage] ); + mMotionBlurImageActor.SetImage(blurImage); + } + + + private: + Application& mApplication; ///< Application instance + Toolkit::View mView; + Toolkit::ToolBar mToolBar; - TextView mTitleActor; ///< The Toolbar's Title. + Image mIconEffectsOff; + Image mIconEffectsOn; + + Layer mContentLayer; ///< Content layer (contains actor for this blur demo) + + PushButton mActorEffectsButton; ///< The actor effects toggling Button. + + // Motion blur + MotionBlurEffect mMotionBlurEffect; + ImageActor mMotionBlurImageActor; + + #ifdef MULTIPLE_MOTION_BLURRED_ACTORS + MotionBlurEffect mMotionBlurEffect2; + MotionBlurEffect mMotionBlurEffect3; + MotionBlurEffect mMotionBlurEffect4; + MotionBlurEffect mMotionBlurEffect5; + + ImageActor mMotionBlurImageActor2; + ImageActor mMotionBlurImageActor3; + ImageActor mMotionBlurImageActor4; + ImageActor mMotionBlurImageActor5; + #endif //#ifdef MULTIPLE_MOTION_BLURRED_ACTORS + + // animate actor to position where user taps screen + Animation mActorTapMovementAnimation; + + // show different animations to demonstrate blur effect working on an object only movement basis + bool mActorEffectsEnabled; + Animation mActorAnimation; + int mCurrentActorAnimation; + + // offer a selection of images that user can cycle between + int mCurrentImage; + + TapGestureDetector mTapGestureDetector; + + DeviceOrientation mOrientation; ///< Current Device orientation + Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. + + Popup mInstructionsPopup; ///< Info Popup + }; + + void RunTest(Application& app) + { + MotionBlurExampleApp test(app); + + app.MainLoop(); + } + + // Entry point for Linux & SLP applications + // + int main(int argc, char **argv) + { + Application app = Application::New(&argc, &argv); + + RunTest(app); + + return 0; + } diff --cc examples/motion-stretch/motion-stretch-example.cpp index 00000000,94b48a8a..00203ea7 mode 000000,100644..100644 --- a/examples/motion-stretch/motion-stretch-example.cpp +++ b/examples/motion-stretch/motion-stretch-example.cpp @@@ -1,0 -1,447 +1,446 @@@ + /* + * 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 + #include + + #include "shared/view.h" + #include + #include + + using namespace Dali; + using namespace Dali::Toolkit; + + + + namespace // unnamed namespace + { + + //////////////////////////////////////////////////// + // + // Demo setup parameters + // + + const float MOTION_STRETCH_ACTOR_WIDTH = 256; // actor size on screen + const float MOTION_STRETCH_ACTOR_HEIGHT = 256; // "" + + const int MOTION_STRETCH_NUM_ACTOR_IMAGES = 5; + const char* MOTION_STRETCH_ACTOR_IMAGE1( DALI_IMAGE_DIR "image-with-border-1.jpg" ); + const char* MOTION_STRETCH_ACTOR_IMAGE2( DALI_IMAGE_DIR "image-with-border-2.jpg" ); + const char* MOTION_STRETCH_ACTOR_IMAGE3( DALI_IMAGE_DIR "image-with-border-3.jpg" ); + const char* MOTION_STRETCH_ACTOR_IMAGE4( DALI_IMAGE_DIR "image-with-border-4.jpg" ); + const char* MOTION_STRETCH_ACTOR_IMAGE5( DALI_IMAGE_DIR "image-with-border-5.jpg" ); + + const char* MOTION_STRETCH_ACTOR_IMAGES[] = { + MOTION_STRETCH_ACTOR_IMAGE1, + MOTION_STRETCH_ACTOR_IMAGE2, + MOTION_STRETCH_ACTOR_IMAGE3, + MOTION_STRETCH_ACTOR_IMAGE4, + MOTION_STRETCH_ACTOR_IMAGE5, + }; + + const int NUM_ACTOR_ANIMATIONS = 4; + const int NUM_CAMERA_ANIMATIONS = 2; + + + const char* BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "background-default.png"; + + const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + const char* LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); + const char* APPLICATION_TITLE( "Motion Stretch" ); + const char* EFFECTS_OFF_ICON( DALI_IMAGE_DIR "icon-effects-off.png" ); + const char* EFFECTS_ON_ICON( DALI_IMAGE_DIR "icon-effects-on.png" ); + + // These values depend on the button background image + const Vector4 BUTTON_IMAGE_BORDER( Vector4::ONE * 3.0f ); + + const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons + + const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); + + // move this button down a bit so it is visible on target and not covered up by toolbar + const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; + + const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. + } // unnamed namespace + + + + + // + class MotionStretchExampleApp : public ConnectionTracker + { + public: + + /** + * DeviceOrientation describes the four different + * orientations the device can be in based on accelerometer reports. + */ + enum DeviceOrientation + { + PORTRAIT = 0, + LANDSCAPE = 90, + PORTRAIT_INVERSE = 180, + LANDSCAPE_INVERSE = 270 + }; + + /** + * Constructor + * @param application class, stored as reference + */ + MotionStretchExampleApp(Application &app) + : mApplication(app), + mActorEffectsEnabled(false), + mCurrentActorAnimation(0), + mCurrentImage(0) + { + // Connect to the Application's Init signal + app.InitSignal().Connect(this, &MotionStretchExampleApp::OnInit); + } + + ~MotionStretchExampleApp() + { + // Nothing to do here; everything gets deleted automatically + } + + /** + * This method gets called once the main loop of application is up and running + */ + void OnInit(Application& app) + { + // The Init signal is received once (only) during the Application lifetime + + Stage::GetCurrent().KeyEventSignal().Connect(this, &MotionStretchExampleApp::OnKeyEvent); + + // Creates a default view with a default tool bar. + // The view is added to the stage. + mContentLayer = DemoHelper::CreateView( mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE_PATH, + TOOLBAR_IMAGE, + APPLICATION_TITLE ); + + //Add an slideshow icon on the right of the title + mIconEffectsOff = ResourceImage::New( EFFECTS_OFF_ICON ); + mIconEffectsOn = ResourceImage::New( EFFECTS_ON_ICON ); + mActorEffectsButton = Toolkit::PushButton::New(); + mActorEffectsButton.SetBackgroundImage( mIconEffectsOff ); + mActorEffectsButton.ClickedSignal().Connect( this, &MotionStretchExampleApp::OnEffectButtonClicked ); + mToolBar.AddControl( mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + + // Creates a mode button. + // Create a effect toggle button. (right of toolbar) + Image imageLayout = ResourceImage::New( LAYOUT_IMAGE ); + Toolkit::PushButton layoutButton = Toolkit::PushButton::New(); + layoutButton.SetBackgroundImage(imageLayout); + layoutButton.ClickedSignal().Connect( this, &MotionStretchExampleApp::OnLayoutButtonClicked); + layoutButton.SetLeaveRequired( true ); + mToolBar.AddControl( layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Input + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mContentLayer ); + mTapGestureDetector.DetectedSignal().Connect( this, &MotionStretchExampleApp::OnTap ); + + // set initial orientation + Dali::Window winHandle = app.GetWindow(); + winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); + winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); + winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); + winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); + + app.GetOrientation().ChangedSignal().Connect( this, &MotionStretchExampleApp::OnOrientationChanged ); + unsigned int degrees = app.GetOrientation().GetDegrees(); + Rotate( static_cast< DeviceOrientation >( degrees ) ); + + + /////////////////////////////////////////////////////// + // + // Motion stretched actor + // + + Image image = ResourceImage::New( MOTION_STRETCH_ACTOR_IMAGE1 ); + mMotionStretchImageActor = ImageActor::New(image); + mMotionStretchImageActor.SetParentOrigin( ParentOrigin::CENTER ); + mMotionStretchImageActor.SetAnchorPoint( AnchorPoint::CENTER ); + mMotionStretchImageActor.SetSize(MOTION_STRETCH_ACTOR_WIDTH, MOTION_STRETCH_ACTOR_HEIGHT); + + mContentLayer.Add( mMotionStretchImageActor ); + + // Create shader used for doing motion stretch + mMotionStretchEffect = MotionStretchEffect::Apply(mMotionStretchImageActor); + } + + ////////////////////////////////////////////////////////////// + // + // Device Orientation Support + // + // + + void OnOrientationChanged( Orientation orientation ) + { + unsigned int degrees = orientation.GetDegrees(); + Rotate( static_cast< DeviceOrientation >( degrees ) ); + } + + void Rotate( DeviceOrientation orientation ) + { + // Resize the root actor + Vector2 stageSize = Stage::GetCurrent().GetSize(); + Vector2 targetSize = stageSize; + if( orientation == LANDSCAPE || + orientation == LANDSCAPE_INVERSE ) + { + targetSize = Vector2( stageSize.y, stageSize.x ); + } + + if( mOrientation != orientation ) + { + mOrientation = orientation; + + // check if actor is on stage + if( mView.GetParent() ) + { + // has parent so we expect it to be on stage, start animation + mRotateAnimation = Animation::New( ORIENTATION_DURATION ); + mRotateAnimation.RotateTo( mView, Degree( -orientation ), Vector3::ZAXIS, AlphaFunctions::EaseOut ); + mRotateAnimation.Resize( mView, targetSize.width, targetSize.height ); + mRotateAnimation.Play(); + } + else + { + // set the rotation to match the orientation + mView.SetRotation( Degree( -orientation ), Vector3::ZAXIS ); + mView.SetSize( targetSize ); + } + } + else + { + // for first time just set size + mView.SetSize( targetSize ); + } + } + + ////////////////////////////////////////////////////////////// + // + // Actor Animation + // + // + + // move to point on screen that was tapped + void OnTap( Actor actor, const TapGesture& tapGesture ) + { + Vector3 destPos; + float originOffsetX, originOffsetY; + + // rotate offset (from top left origin to centre) into actor space + Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + actor.ScreenToLocal(originOffsetX, originOffsetY, stageSize.width * 0.5f, stageSize.height * 0.5f); + + // get dest point in local actor space + destPos.x = tapGesture.localPoint.x - originOffsetX; + destPos.y = tapGesture.localPoint.y - originOffsetY; + destPos.z = 0.0f; + + float animDuration = 0.5f; + mActorTapMovementAnimation = Animation::New( animDuration ); + if ( mMotionStretchImageActor ) + { + mActorTapMovementAnimation.AnimateTo( Property(mMotionStretchImageActor, Actor::Property::Position), destPos, AlphaFunctions::EaseInOutSine, TimePeriod(animDuration) ); + } + mActorTapMovementAnimation.SetEndAction( Animation::Bake ); + mActorTapMovementAnimation.Play(); + + + // perform some spinning etc + if(mActorEffectsEnabled) + { + switch(mCurrentActorAnimation) + { + // spin around y + case 0: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionStretchImageActor, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // spin around z + case 1: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionStretchImageActor, Degree(720), Vector3::ZAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // spin around y and z + case 2: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.RotateBy(mMotionStretchImageActor, Degree(360), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.RotateBy(mMotionStretchImageActor, Degree(360), Vector3::ZAXIS, AlphaFunctions::EaseInOut); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + // scale + case 3: + { + float animDuration = 1.0f; + mActorAnimation = Animation::New(animDuration); + mActorAnimation.ScaleBy(mMotionStretchImageActor, Vector3(2.0f, 2.0f, 2.0f), AlphaFunctions::Bounce, 0.0f, 1.0f); + mActorAnimation.SetEndAction( Animation::Bake ); + mActorAnimation.Play(); + } + break; + + default: + break; + } + + mCurrentActorAnimation++; + if(NUM_ACTOR_ANIMATIONS == mCurrentActorAnimation) + { + mCurrentActorAnimation = 0; + } + } + } + + void ToggleActorEffects() + { + if(!mActorEffectsEnabled) + { + mActorEffectsEnabled = true; + mActorEffectsButton.SetBackgroundImage( mIconEffectsOn ); + } + else + { + mActorEffectsEnabled = false; + mActorEffectsButton.SetBackgroundImage( mIconEffectsOff ); + } + } + + ////////////////////////////////////////////////////////////// + // + // Input handlers + // + // + + bool OnLayoutButtonClicked( Toolkit::Button button ) + { + ChangeImage(); + return true; + } + + bool OnEffectButtonClicked( Toolkit::Button button ) + { + ToggleActorEffects(); + return true; + } + + /** + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + ////////////////////////////////////////////////////////////// + // + // Misc + // + // + + + void ChangeImage() + { + mCurrentImage++; + if(MOTION_STRETCH_NUM_ACTOR_IMAGES == mCurrentImage) + { + mCurrentImage = 0; + } + + Image stretchImage = ResourceImage::New( MOTION_STRETCH_ACTOR_IMAGES[mCurrentImage] ); + mMotionStretchImageActor.SetImage(stretchImage); + } + + + private: + Application& mApplication; ///< Application instance + Toolkit::View mView; + Toolkit::ToolBar mToolBar; - TextView mTitleActor; ///< The Toolbar's Title. + Image mIconEffectsOff; + Image mIconEffectsOn; + Layer mContentLayer; ///< Content layer (contains actor for this stretch demo) + + PushButton mActorEffectsButton; ///< The actor effects toggling Button. + + // Motion stretch + MotionStretchEffect mMotionStretchEffect; + ImageActor mMotionStretchImageActor; + + // animate actor to position where user taps screen + Animation mActorTapMovementAnimation; + + // show different animations to demonstrate stretch effect working on an object only movement basis + bool mActorEffectsEnabled; + Animation mActorAnimation; + int mCurrentActorAnimation; + + // offer a selection of images that user can cycle between + int mCurrentImage; + + TapGestureDetector mTapGestureDetector; + + DeviceOrientation mOrientation; ///< Current Device orientation + Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. + + }; + + void RunTest(Application& app) + { + MotionStretchExampleApp test(app); + + app.MainLoop(); + } + + // Entry point for Linux & SLP applications + // + int main(int argc, char **argv) + { + Application app = Application::New(&argc, &argv); + + RunTest(app); + + return 0; + } diff --cc examples/new-window/new-window-example.cpp index 3a1f9892,59523083..e6e35f05 --- a/examples/new-window/new-window-example.cpp +++ b/examples/new-window/new-window-example.cpp @@@ -82,9 -79,8 +79,7 @@@ public private: Application mApplication; - Animation mModelAnimation; - Actor mModelActor; Actor mCastingLight; - TextActor mTextActor; ImageActor mImageActor; ImageActor mBlendActor; Image mEffectImage; diff --cc examples/path-animation/path-animation.cpp index 00000000,e4b12a3a..9f924e06 mode 000000,100644..100644 --- a/examples/path-animation/path-animation.cpp +++ b/examples/path-animation/path-animation.cpp @@@ -1,0 -1,464 +1,365 @@@ + /* + * 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. + * + */ + + /** + * This example shows how to use path animations in DALi + */ + + // EXTERNAL INCLUDES + #include + + // INTERNAL INCLUDES + #include "shared/view.h" + + using namespace Dali; + using namespace Dali::Toolkit; + + + namespace + { + const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); + const char* ACTOR_IMAGE( DALI_IMAGE_DIR "dali-logo.png" ); + const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Path Example" ); + }; //Unnamed namespace + + /** + * @brief The main class of the demo. + */ + class PathController : public ConnectionTracker + { + public: + + PathController( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &PathController::Create ); + } + + ~PathController() + { + // Nothing to do here. + } + + /** + * One-time setup in response to Application InitSignal. + */ + void Create( Application& application ) + { + // Get a handle to the stage: + Stage stage = Stage::GetCurrent(); + + // Connect to input event signals: + stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent); + + // Create a default view with a default tool bar: + Toolkit::View view; ///< The View instance. + Toolkit::ToolBar toolBar; ///< The View's Toolbar. + mContentLayer = DemoHelper::CreateView( mApplication, + view, + toolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + "" ); + + mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer); + - //Title - TextView title = TextView::New(); - toolBar.AddControl( title, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); - Font font = Font::New(); - title.SetText( APPLICATION_TITLE ); - title.SetSize( font.MeasureText( APPLICATION_TITLE ) ); - title.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); - + //Path + mPath = Dali::Path::New(); + mPath.AddPoint( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f )); + mPath.AddPoint( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.3f, 0.0f )); + mPath.GenerateControlPoints(0.25f); + DrawPath( 200u ); + + //Actor + ImageAttributes attributes; + Image img = ResourceImage::New(ACTOR_IMAGE, attributes ); + mActor = ImageActor::New( img ); + mActor.SetPosition( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ) ); + mActor.SetAnchorPoint( AnchorPoint::CENTER ); + mActor.SetSize( 100, 50, 1 ); + stage.Add( mActor ); + + mForward = Vector3::XAXIS; + CreateAnimation(); - - Dali::TextActor forwardLabel = TextActor::New("Forward Vector"); - forwardLabel.SetPosition( 10.0f, stage.GetSize().y - 60.0f, 0.0f ); - forwardLabel.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - forwardLabel.SetAnchorPoint( AnchorPoint::CENTER_LEFT); - mContentLayer.Add( forwardLabel ); - - //TextInput - Dali::Layer textInputLayer = Dali::Layer::New(); - textInputLayer.SetSize( 400.0f, 30.0f, 0.0 ); - textInputLayer.SetPosition( 0.0f, stage.GetSize().y - 30.0f, 0.0f ); - textInputLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); - textInputLayer.SetParentOrigin( ParentOrigin::TOP_LEFT); - stage.Add( textInputLayer ); - Dali::TextActor label = TextActor::New("X:"); - label.SetPosition( 10.0f, 0.0f, 0.0f ); - label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT); - textInputLayer.Add( label ); - TextStyle style; - style.SetTextColor( Vector4( 0.0f, 0.0f ,0.0f, 1.0f )); - mTextInput[0] = TextInput::New(); - mTextInput[0].SetInitialText("1.0"); - mTextInput[0].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - mTextInput[0].SetAnchorPoint( AnchorPoint::CENTER_LEFT); - mTextInput[0].SetParentOrigin( ParentOrigin::CENTER_RIGHT); - mTextInput[0].SetPosition( 10.0f, 0.0f, 0.0f ); - mTextInput[0].SetSize( 70.0f, 0.0f, 0.0f ); - mTextInput[0].SetTextAlignment(Alignment::HorizontalCenter ); - mTextInput[0].SetMaxCharacterLength( 5 ); - mTextInput[0].SetNumberOfLinesLimit(1); - mTextInput[0].ApplyStyleToAll( style ); - mTextInput[0].SetProperty( mTextInput[0].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) ); - mTextInput[0].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f)); - mTextInput[0].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd); - mTextInput[0].SetEditOnTouch(); - label.Add( mTextInput[0]); - label = TextActor::New("Y:"); - label.SetPosition( 160.0f,0.0f, 0.0f ); - label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT); - textInputLayer.Add( label ); - mTextInput[1] = TextInput::New(); - mTextInput[1].SetInitialText("0.0"); - mTextInput[1].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - mTextInput[1].SetAnchorPoint( AnchorPoint::CENTER_LEFT); - mTextInput[1].SetParentOrigin( ParentOrigin::CENTER_RIGHT); - mTextInput[1].SetPosition( 10.0f, 0.0f, 0.0f ); - mTextInput[1].SetSize( 70.0f, 0.0f, 0.0f ); - mTextInput[1].SetTextAlignment(Alignment::HorizontalCenter ); - mTextInput[1].SetMaxCharacterLength( 5 ); - mTextInput[1].SetNumberOfLinesLimit(1); - mTextInput[1].ApplyStyleToAll( style ); - mTextInput[1].SetProperty( mTextInput[1].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) ); - mTextInput[1].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f)); - mTextInput[1].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd); - label.Add( mTextInput[1]); - label = TextActor::New("Z:"); - label.SetPosition( 310.0f, 0.0f, 0.0f ); - label.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT); - textInputLayer.Add( label ); - mTextInput[2] = TextInput::New(); - mTextInput[2].SetInitialText("0.0"); - mTextInput[2].SetColor( Vector4(0.0f,0.0f,0.0f,1.0f)); - mTextInput[2].SetAnchorPoint( AnchorPoint::CENTER_LEFT); - mTextInput[2].SetParentOrigin( ParentOrigin::CENTER_RIGHT); - mTextInput[2].SetPosition( 10.0f, 0.0f, 0.0f ); - mTextInput[2].SetSize( 70.0f, 0.0f, 0.0f ); - mTextInput[2].SetTextAlignment(Alignment::HorizontalCenter ); - mTextInput[2].SetMaxCharacterLength( 5 ); - mTextInput[2].SetNumberOfLinesLimit(1); - mTextInput[2].ApplyStyleToAll( style ); - mTextInput[2].SetProperty( mTextInput[2].GetPropertyIndex("cursor-color"), Vector4(0.0f,0.0f,0.0f,1.0f) ); - mTextInput[2].SetBackgroundColor( Vector4(0.8f,1.0f,0.8f, 0.4f)); - mTextInput[2].InputFinishedSignal().Connect(this, &PathController::OnTextInputEnd); - label.Add( mTextInput[2]); + } + + /** + * Create an actor representing a control point of the curve + * @param[in] name Name of the actor + * @param[in] size Size of the containing actor + * @param[in] imageSize Size of the imageActor + * @param[in] color Color of the imageActor + */ + Actor CreateControlPoint(const std::string& name, const Vector3& size, const Vector3& imageSize, const Vector4& color ) + { + Actor actor = Actor::New(); + actor.SetParentOrigin( ParentOrigin::TOP_LEFT); + actor.SetAnchorPoint( AnchorPoint::CENTER ); + actor.SetSize( size ); + actor.SetName( name ); + actor.TouchedSignal().Connect(this, &PathController::OnTouchPoint); + + ImageActor imageActor = Toolkit::CreateSolidColorActor(color); + imageActor.SetColor(Vector4(1.0f,0.0f,0.0f,1.0f)); + imageActor.SetParentOrigin( ParentOrigin::CENTER); + imageActor.SetAnchorPoint( AnchorPoint::CENTER ); + imageActor.SetSize( imageSize ); + actor.Add(imageActor ); + + return actor; + } + + /** + * Draws the path and the control points for the path + * @param[in] resolution Number of segments for the path. + */ + void DrawPath( unsigned int resolution ) + { + Stage stage = Dali::Stage::GetCurrent(); + + //Create path mesh actor + Dali::MeshData meshData = MeshFactory::NewPath( mPath, resolution ); + Dali::Material material = Material::New("LineMaterial"); + material.SetDiffuseColor( Vector4(0.0f,0.0f,0.0f,1.0f)); + meshData.SetMaterial(material); + Dali::Mesh mesh = Dali::Mesh::New( meshData ); + if( mMeshPath ) + { + stage.Remove( mMeshPath ); + } + mMeshPath = Dali::MeshActor::New( mesh ); + mMeshPath.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mMeshPath.SetParentOrigin( ParentOrigin::TOP_LEFT ); + stage.Add( mMeshPath ); + + + ////Create mesh connecting interpolation points and control points + std::vector vVertex; + std::vector vIndex; + size_t pointCount = mPath.GetPointCount(); + size_t controlPointIndex = 0; + for( size_t i(0); i0) + { + const TouchPoint& point = event.GetPoint(0); + + if(point.state==TouchPoint::Down) + { + // Start dragging + mDragActor = actor; + } + } + return false; + } + + bool OnTouchLayer(Actor actor, const TouchEvent& event) + { + if(event.GetPointCount()>0) + { + const TouchPoint& point = event.GetPoint(0); + + if(point.state==TouchPoint::Up) + { + //Stop dragging + mDragActor.Reset(); + } + else if(!mDragActor && point.state==TouchPoint::Down && mPath.GetPointCount()<10 ) + { + // Add new point + const TouchPoint& point = event.GetPoint(0); + Vector3 newPoint = Vector3(point.screen.x, point.screen.y, 0.0f); + + size_t pointCount = mPath.GetPointCount(); + Vector3 lastPoint = mPath.GetPoint( pointCount-1); + mPath.AddPoint( newPoint ); + + Vector3 displacement = (newPoint-lastPoint)/8; + + mPath.AddControlPoint( lastPoint + displacement ); + mPath.AddControlPoint( newPoint - displacement); + + DrawPath( 200u ); + CreateAnimation(); + } + else + { + if( mDragActor ) + { + const TouchPoint& point = event.GetPoint(0); + Vector3 newPosition = Vector3(point.screen.x, point.screen.y, 0.0f); + + std::string actorName(mDragActor.GetName()); + + if( actorName.compare(0, 4, "Knot") == 0) + { + int index = actorName[4]; + mPath.GetPoint(index) = newPosition; + } + else + { + int index = actorName[12]; + mPath.GetControlPoint(index) = newPosition; + } + + DrawPath( 200u ); + CreateAnimation(); + } + } + } + return false; + } + + /** + * Main key event handler. + * Quit on escape key. + */ + void OnKeyEvent(const KeyEvent& event) + { + if( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || + IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + - /** - * Callback called when user end to input text in any of the TextInput - * @param[in] textInput The text input that has generated the signal - */ - void OnTextInputEnd( TextInput textInput) - { - mForward.x = (float)atof( mTextInput[0].GetText().c_str() ); - mForward.y = (float)atof( mTextInput[1].GetText().c_str() ); - mForward.z = (float)atof( mTextInput[2].GetText().c_str() ); - CreateAnimation(); - } - + /** + * Create the path animation. + */ + void CreateAnimation() + { + if( !mAnimation ) + { + mAnimation = Animation::New( 2.0f ); + } + else + { + mAnimation.Pause(); + mAnimation.Clear(); + mActor.SetRotation( Quaternion() ); + } + + mAnimation.Animate( mActor, mPath, mForward ); + mAnimation.SetLooping( true ); + mAnimation.Play(); + } + + private: + Application& mApplication; + + Layer mContentLayer; ///< The content layer + + Path mPath; ///< The path used in the animation + ImageActor mActor; ///< Actor being animated + Vector3 mForward; ///< Current forward vector + Animation mAnimation; ///< Path animation + + MeshActor mMeshPath; ///< Mesh actor for the path + MeshActor mMeshHandlers; ///< Mesh actor for the segments connecting points and control points + Actor mKnot[10]; ///< ImageActors for the interpolation points + Actor mControlPoint[18]; ///< ImageActors for the control points + + Actor mDragActor; ///< Reference to the actor currently being dragged - TextInput mTextInput[3]; ///< Text input to specify forward vector of the path animation + }; + + void RunTest( Application& application ) + { + PathController test( application ); + + application.MainLoop(); + } + + /** Entry point for Linux & Tizen applications */ + int main( int argc, char **argv ) + { + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; + } diff --cc examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp index 00000000,1f423296..92f31cb8 mode 000000,100644..100644 --- a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp +++ b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp @@@ -1,0 -1,532 +1,485 @@@ + /* + * 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. + * + */ + + // INTERNAL INCLUDES + #include "shared/view.h" + + #include + #include + #include + + using namespace Dali; + using namespace Dali::Toolkit; + using std::string; + using namespace DemoHelper; + + namespace + { + const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" ); + const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); + -const char* APPLICATION_TITLE_PAN_LIGHT( "Lighting: Pan Light" ); -const char* APPLICATION_TITLE_PAN_OBJECT( "Lighting: Pan Object" ); -const char* APPLICATION_TITLE_PAN_SCENE( "Lighting: Pan Scene" ); -const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); ++//const char* APPLICATION_TITLE_PAN_LIGHT( "Lighting: Pan Light" ); ++//const char* APPLICATION_TITLE_PAN_OBJECT( "Lighting: Pan Object" ); ++//const char* APPLICATION_TITLE_PAN_SCENE( "Lighting: Pan Scene" ); ++//const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); + const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); + const char* RESET_ICON( DALI_IMAGE_DIR "icon-reset.png" ); + + const char* SCENE_IMAGE_1( DALI_IMAGE_DIR "gallery-small-10.jpg"); + const char* SCENE_IMAGE_2( DALI_IMAGE_DIR "gallery-small-42.jpg"); + const char* SCENE_IMAGE_3( DALI_IMAGE_DIR "gallery-small-48.jpg"); + + const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles + const float MIN_PINCH_SCALE( 0.3f ); + const float MAX_PINCH_SCALE( 2.05f ); + + const float R3_2(0.8660254); + const Vector3 TOP_POINT( 0.0f, -1.0f, 0.0f); + const Vector3 LEFT_POINT( -R3_2, 0.5f, 0.0f); + const Vector3 RIGHT_POINT( R3_2, 0.5f, 0.0f); + const Vector3 FRONT_POINT( 0.0f, 0.0f, 20.0f); + + const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f ); + + } + + /** + * This example shows a fixed point light onto an animating set of images + * casting a shadow onto a wall. The whole scene can be rotated. + */ + + class TestApp : public ConnectionTracker + { + public: + + /** + * Constructor + * @param application class, stored as reference + */ + TestApp(Application &app) + : mApp(app), + mPaused(false), + mTranslation(Vector3::ZERO), + mLongitudinal(15.0f), + mAxisTilt(30.0f), + mLightLongitudinal(0.0f), + mLightAxisTilt(0.0f), + mObjectLongitudinal(0.0f), + mObjectAxisTilt(0.0f), + mPinchScale(0.5f), + mScaleAtPinchStart(0.5f), + mPanState(PAN_SCENE) + { + app.InitSignal().Connect(this, &TestApp::Create); + app.TerminateSignal().Connect(this, &TestApp::Terminate); + } + + ~TestApp() + { + // Nothing to do here; All the members of this class get deleted automatically and they delete their children + } + + public: + struct PositionInFrontOf + { + PositionInFrontOf() + { + } + + Vector3 operator()( const Vector3& current, const PropertyInput& property ) + { + Vector3 position = property.GetVector3(); + position.z += 1.0f; + return position; + } + }; + + struct QuaternionEqualToConstraint + { + QuaternionEqualToConstraint() + { + } + + Quaternion operator()( const Quaternion& current, const PropertyInput& property ) + { + return property.GetQuaternion(); + } + }; + + struct RotationConstraint + { + RotationConstraint(float sign) + : mSign(sign) + { + } + + Quaternion operator()( const Quaternion& current, const PropertyInput& property ) + { + Degree angle(property.GetFloat()); + return Quaternion( Radian(angle) * mSign, Vector3::YAXIS ); + } + + float mSign; + }; + + /** + * This method gets called once the main loop of application is up and running + */ + void Create(Application& app) + { + srand(0); // Want repeatable path + + Stage::GetCurrent().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); + + CreateToolbarAndView(app); + CreateShadowViewAndLights(); + CreateScene(); + } + + void CreateToolbarAndView(Application& app) + { + // Creates a default view with a default tool bar. + // The view is added to the stage. + Toolkit::ToolBar toolBar; + mContents = DemoHelper::CreateView( app, + mView, + toolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + "" ); + + // Add an effect-changing button on the right of the tool bar. + Image imageChangeEffect = ResourceImage::New( CHANGE_EFFECT_IMAGE ); + Toolkit::PushButton effectChangeButton = Toolkit::PushButton::New(); + effectChangeButton.SetBackgroundImage(imageChangeEffect); + effectChangeButton.ClickedSignal().Connect( this, &TestApp::OnEffectButtonClicked ); + toolBar.AddControl( effectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Add title to the tool bar. - mTitleActor = Toolkit::TextView::New(); - toolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); - - // Set Title text - mTitleActor.SetText( APPLICATION_TITLE_PAN_SCENE ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_PAN_SCENE ) ); - mTitleActor.SetStyleToCurrentText( DemoHelper::GetDefaultTextStyle() ); ++ // TODO + + //Add a reset button + Image resetImage = ResourceImage::New( RESET_ICON ); + Toolkit::PushButton resetButton = Toolkit::PushButton::New(); + resetButton.SetBackgroundImage( resetImage ); + resetButton.ClickedSignal().Connect( this, &TestApp::OnResetPressed ); + toolBar.AddControl( resetButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + + // Setup + mView.SetPosition(Vector3(0.0f, 0.0f, -50)); + + mContents.SetPosition(mTranslation); + mContents.SetRotation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt))); + mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); + + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.Attach( mView ); + mPanGestureDetector.DetectedSignal().Connect(this, &TestApp::OnPan); + + mPinchGestureDetector = PinchGestureDetector::New(); + mPinchGestureDetector.Attach( mView ); + mPinchGestureDetector.DetectedSignal().Connect(this, &TestApp::OnPinch); + + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mView ); + mTapGestureDetector.DetectedSignal().Connect(this, &TestApp::OnTap); + } + + + + void CreateShadowViewAndLights() + { + mShadowView = Toolkit::ShadowView::New(); + mShadowView.SetName("Container"); + mShadowView.SetParentOrigin(ParentOrigin::CENTER); + mShadowView.SetAnchorPoint(AnchorPoint::CENTER); + mShadowView.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f); + mContents.Add(mShadowView); + + Image brickWall = ResourceImage::New(DALI_IMAGE_DIR "brick-wall.jpg"); + mShadowPlaneBg = ImageActor::New(brickWall); + mShadowPlaneBg.SetParentOrigin(ParentOrigin::CENTER); + mShadowPlaneBg.SetAnchorPoint(AnchorPoint::CENTER); + mShadowPlaneBg.SetName("Plane"); + mShadowPlaneBg.SetSize(1000.0f, 1000.0f); + mContents.Add(mShadowPlaneBg); + mShadowPlaneBg.SetPosition(Vector3(50.0f, 50.0f, -200.0f)); + + mShadowView.SetShadowPlane(mShadowPlaneBg); + mShadowView.Activate(); + + mLightAnchor = Actor::New(); + mLightAnchor.SetParentOrigin(ParentOrigin::CENTER); + mLightAnchor.SetAnchorPoint(AnchorPoint::CENTER); + mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt))); + + // Work out a scaling factor as the initial light position was calculated for desktop + // Need to scale light position as scene actor size is based on stage size (i.e. much bigger on device) + Vector2 stageSize( Stage::GetCurrent().GetSize() ); + float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x; + + mCastingLight = Actor::New(); + mCastingLight.SetParentOrigin(ParentOrigin::CENTER); + mCastingLight.SetAnchorPoint(AnchorPoint::CENTER); + mCastingLight.SetPosition( Vector3( 0.0f, 0.0f, 800.0f ) * scaleFactor ); + - TextStyle style; - style.SetFontPointSize( PointSize(DemoHelper::ScalePointSize(20.0f)) ); - style.SetFontName("Times New Roman"); - style.SetFontStyle("Book"); - - TextActorParameters parameters( style, TextActorParameters::FONT_DETECTION_ON ); - TextActor text = TextActor::New("Light", parameters); - text.SetColor(Color::BLUE); - - mCastingLight.Add(text); + mLightAnchor.Add(mCastingLight); + mShadowPlaneBg.Add(mLightAnchor); + - text.SetParentOrigin(ParentOrigin::CENTER); + mShadowView.SetPointLight(mCastingLight); + } + + void CreateScene() + { + mSceneActor = Actor::New(); + mSceneActor.SetParentOrigin(ParentOrigin::CENTER); + + // Create and add images to the scene actor: + mImageActor1 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_1) ); + mImageActor2 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_2) ); + mImageActor3 = ImageActor::New( ResourceImage::New(SCENE_IMAGE_3) ); + + + mImageActor2.SetParentOrigin(ParentOrigin::CENTER); + + mImageActor1.SetParentOrigin(ParentOrigin::CENTER_LEFT); + mImageActor1.SetAnchorPoint(AnchorPoint::CENTER_RIGHT); + + mImageActor3.SetParentOrigin(ParentOrigin::CENTER_RIGHT); + mImageActor3.SetAnchorPoint(AnchorPoint::CENTER_LEFT); + + mSceneActor.Add(mImageActor2); + mImageActor2.Add(mImageActor1); + mImageActor2.Add(mImageActor3); + + Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(30.0f)); + Source angleSrc( mImageActor2, angleIndex ); + mImageActor1.ApplyConstraint(Constraint::New( Actor::Property::Rotation, angleSrc, + RotationConstraint(-1.0f))); + mImageActor3.ApplyConstraint(Constraint::New( Actor::Property::Rotation, angleSrc, + RotationConstraint(+1.0f))); + + mSceneAnimation = Animation::New(2.5f); + + // Want to animate angle from 30 => -30 and back again smoothly. + + mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-30.0f), AlphaFunctions::Sin ); + + mSceneAnimation.SetLooping(true); + mSceneAnimation.Play(); + + mSceneActor.SetSize(250.0f, 250.0f); + mSceneActor.SetPosition(0.0f, 0.0f, 130.0f); + mShadowView.Add(mSceneActor); + } + + + Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt ) + { + Quaternion q(longitude, Vector3::YAXIS); + Quaternion p(axisTilt, Vector3::XAXIS); + return p*q; + } + + void OnTap(Dali::Actor actor, const TapGesture& gesture) + { + if( mSceneAnimation ) + { + if( ! mPaused ) + { + mSceneAnimation.Pause(); + mPaused = true; + } + else + { + mSceneAnimation.Play(); + mPaused = false; + } + } + } + + void OnPan(Actor actor, const PanGesture& gesture) + { + switch (gesture.state) + { + case Gesture::Continuing: + { + switch(mPanState) + { + case PAN_LIGHT: + { + mLightLongitudinal += gesture.displacement.x/4.0f; + mLightAxisTilt -= gesture.displacement.y/6.0f; + mLightAxisTilt = Clamp(mLightAxisTilt, -90.0f, 90.0f); + mLightAnchor.SetRotation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt))); + break; + } + + case PAN_SCENE: + { + mTranslation += Vector3(gesture.displacement.x, gesture.displacement.y, 0.f); + mContents.SetPosition(mTranslation); + break; + } + + case ROTATE_SCENE: + { + mLongitudinal += gesture.displacement.x/4.0f; + mAxisTilt -= gesture.displacement.y/6.0f; + mAxisTilt = Clamp(mAxisTilt, -90.0f, 90.0f); + mContents.SetRotation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt))); + break; + } + + case PAN_OBJECT: + { + mObjectLongitudinal += gesture.displacement.x/4.0f; + mObjectAxisTilt -= gesture.displacement.y/6.0f; + mObjectAxisTilt = Clamp(mObjectAxisTilt, -90.0f, 90.0f); + mSceneActor.SetRotation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt))); + break; + } + } + } + break; + + case Gesture::Finished: + // Start animation at last known speed + break; + + default: + break; + } + } + + void OnPinch(Actor actor, const PinchGesture& gesture) + { + if (gesture.state == Gesture::Started) + { + mScaleAtPinchStart = mContents.GetCurrentScale().x; + } + mPinchScale = Clamp(mScaleAtPinchStart * gesture.scale, MIN_PINCH_SCALE, MAX_PINCH_SCALE); + + mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); + } + + void Terminate(Application& app) + { + if( mSceneActor ) + { + Stage::GetCurrent().Remove(mSceneActor); + } + if( mView ) + { + Stage::GetCurrent().Remove(mView); + } + } + + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApp.Quit(); + } + } + } + + bool OnEffectButtonClicked( Toolkit::Button button ) + { - switch(mPanState) - { - case PAN_SCENE: - mPanState = ROTATE_SCENE; - mTitleActor.SetText( APPLICATION_TITLE_ROTATE_SCENE ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_ROTATE_SCENE ) ); - break; - case ROTATE_SCENE: - mPanState = PAN_LIGHT; - mTitleActor.SetText( APPLICATION_TITLE_PAN_LIGHT ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_PAN_LIGHT ) ); - break; - case PAN_LIGHT: - mPanState = PAN_OBJECT; - mTitleActor.SetText( APPLICATION_TITLE_PAN_OBJECT ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_PAN_OBJECT ) ); - break; - case PAN_OBJECT: - mPanState = PAN_SCENE; - mTitleActor.SetText( APPLICATION_TITLE_PAN_SCENE ); - mTitleActor.SetSize( Font::New().MeasureText( APPLICATION_TITLE_PAN_SCENE ) ); - break; - default: - break; - } - - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); - + return true; + } + + bool OnResetPressed( Toolkit::Button button ) + { + // Reset translation + mTranslation = Vector3::ZERO; + mContents.SetPosition(mTranslation); + + // Align scene so that light anchor orientation is Z Axis + mAxisTilt = -mLightAxisTilt; + mLongitudinal = -mLightLongitudinal; + mContents.SetRotation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt))); + + return true; + } + + private: + Application& mApp; + Toolkit::View mView; + Layer mContents; + Actor mSceneActor; + Animation mAnimation; + Animation mSceneAnimation; + bool mPaused; + Toolkit::ShadowView mShadowView; + ImageActor mShadowPlaneBg; + ImageActor mShadowPlane; + Actor mCastingLight; + Actor mLightAnchor; + ImageActor mImageActor1; + ImageActor mImageActor2; + ImageActor mImageActor3; + PanGestureDetector mPanGestureDetector; + PinchGestureDetector mPinchGestureDetector; + TapGestureDetector mTapGestureDetector; + Vector3 mTranslation; + Degree mLongitudinal; + Degree mAxisTilt; + Degree mLightLongitudinal; + Degree mLightAxisTilt; + Degree mObjectLongitudinal; + Degree mObjectAxisTilt; + float mPinchScale; + float mScaleAtPinchStart; + + Property::Index mAngle1Index; + Property::Index mAngle3Index; + - Toolkit::TextView mTitleActor; - + enum PanState + { + PAN_SCENE, + ROTATE_SCENE, + PAN_LIGHT, + PAN_OBJECT + }; + + PanState mPanState; + }; + + /*****************************************************************************/ + + static void + RunTest(Application& app) + { + TestApp theApp(app); + app.MainLoop(); + } + + /*****************************************************************************/ + + int + main(int argc, char **argv) + { + Application app = Application::New(&argc, &argv); + + RunTest(app); + + return 0; + } diff --cc examples/text-field/edit-layout-impl.cpp index 00000000,00000000..16e8146a new file mode 100644 --- /dev/null +++ b/examples/text-field/edit-layout-impl.cpp @@@ -1,0 -1,0 +1,106 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "edit-layout-impl.h" ++ ++// INTERNAL INCLUDES ++#include "edit-layout.h" ++ ++namespace ++{ ++ ++const float INNER_BORDER_TOP = 4.0f; ++const float INNER_BORDER_LEFT = 20.0f; ++const float INNER_BORDER_RIGHT = 20.0f; ++ ++} ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++Toolkit::EditLayout EditLayout::New() ++{ ++ // Create the implementation, temporarily owned by this handle on stack ++ IntrusivePtr< EditLayout > impl = new EditLayout(); ++ ++ // Pass ownership to CustomActor handle ++ Toolkit::EditLayout handle( *impl ); ++ ++ // Second-phase init of the implementation ++ // This can only be done after the CustomActor connection has been made... ++ impl->Initialize(); ++ ++ return handle; ++} ++ ++void EditLayout::SetTopPanel( Dali::Toolkit::Control panel ) ++{ ++ mTopPanel = panel; ++ mTopPanel.SetParentOrigin( ParentOrigin::TOP_CENTER ); ++ mTopPanel.SetAnchorPoint( AnchorPoint::TOP_CENTER ); ++ mTopPanel.SetY( INNER_BORDER_TOP ); ++ ++ Self().Add( panel ); ++} ++ ++EditLayout::EditLayout() ++: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) ++{ ++} ++ ++EditLayout::~EditLayout() ++{ ++} ++ ++void EditLayout::OnInitialize() ++{ ++ CustomActor self = Self(); ++ ++ // Move background behind text label ++ Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Color::BLUE ); ++ self.GetChildAt(0).SetZ(-1.0f); ++} ++ ++void EditLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) ++{ ++ CustomActor self = Self(); ++ ++ if( self.GetChildCount() > 0 ) ++ { ++ if( mTopPanel ) ++ { ++ float panelWidth = size.width - INNER_BORDER_LEFT - INNER_BORDER_RIGHT; ++ ++ float height = mTopPanel.GetHeightForWidth( panelWidth ); ++ ++ container.push_back( ActorSizePair( mTopPanel, Vector2(panelWidth, height) ) ); ++ } ++ } ++} ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-field/edit-layout-impl.h index 00000000,00000000..a710de81 new file mode 100644 --- /dev/null +++ b/examples/text-field/edit-layout-impl.h @@@ -1,0 -1,0 +1,79 @@@ ++#ifndef __DALI_DEMO_EDIT_LAYOUT_IMPL_H__ ++#define __DALI_DEMO_EDIT_LAYOUT_IMPL_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// INTERNAL INCLUDES ++#include "edit-layout.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++class EditLayout : public Control ++{ ++public: ++ /** ++ * @copydoc Dali::Toollkit::TextLabel::New() ++ */ ++ static Toolkit::EditLayout New(); ++ ++ /** ++ * @copydoc Dali::Toolkit::EditLayout::SetTopPanel() ++ */ ++ void SetTopPanel( Dali::Toolkit::Control panel ); ++ ++ EditLayout(); ++ ++ virtual ~EditLayout(); ++ ++ /** ++ * @copydoc Control::OnInitialize() ++ */ ++ virtual void OnInitialize(); ++ ++ // Size negotiation methods inherited from Internal::Control ++ ++ /** ++ * @copydoc Control::OnRelayout() ++ */ ++ virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); ++ ++private: ++ ++ // Undefined copy constructor and assignment operators ++ EditLayout(const EditLayout&); ++ EditLayout& operator=(const EditLayout& rhs); ++ ++private: ++ ++ Dali::Toolkit::Control mTopPanel; ++}; ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_EDIT_LAYOUT_IMPL_H__ diff --cc examples/text-field/edit-layout.cpp index 00000000,00000000..81ab94bb new file mode 100644 --- /dev/null +++ b/examples/text-field/edit-layout.cpp @@@ -1,0 -1,0 +1,88 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "edit-layout.h" ++ ++// INTERNAL INCLUDES ++#include "edit-layout-impl.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++EditLayout EditLayout::New() ++{ ++ return Internal::EditLayout::New(); ++} ++ ++void EditLayout::SetTopPanel( Control panel ) ++{ ++ GetImpl( *this ).SetTopPanel( panel ); ++} ++ ++EditLayout::EditLayout() ++{ ++} ++ ++EditLayout::EditLayout( const EditLayout& handle ) ++: Control( handle ) ++{ ++} ++ ++EditLayout& EditLayout::operator=( const EditLayout& handle ) ++{ ++ if( &handle != this ) ++ { ++ Control::operator=( handle ); ++ } ++ return *this; ++} ++ ++EditLayout EditLayout::DownCast( BaseHandle handle ) ++{ ++ return Control::DownCast( handle ); ++} ++ ++EditLayout::~EditLayout() ++{ ++} ++ ++EditLayout::EditLayout( Internal::EditLayout& internal ) ++: Control( internal ) ++{ ++} ++ ++EditLayout::EditLayout( Dali::Internal::CustomActor* internal ) ++: Control( internal ) ++{ ++} ++ ++Internal::EditLayout& EditLayout::GetImpl( EditLayout& verticalLayout ) ++{ ++ DALI_ASSERT_ALWAYS( verticalLayout ); ++ ++ Dali::RefObject& handle = verticalLayout.GetImplementation(); ++ ++ return static_cast(handle); ++} ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-field/edit-layout.h index 00000000,00000000..d8ef906e new file mode 100644 --- /dev/null +++ b/examples/text-field/edit-layout.h @@@ -1,0 -1,0 +1,65 @@@ ++#ifndef __DALI_DEMO_EDIT_LAYOUT_H__ ++#define __DALI_DEMO_EDIT_LAYOUT_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// EXTERNAL INCLUDES ++#include ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++class EditLayout; ++} // namespace Internal ++ ++class EditLayout : public Toolkit::Control ++{ ++public: ++ static EditLayout New(); ++ ++ void SetTopPanel( Control panel ); ++ ++ EditLayout(); ++ ++ EditLayout( const EditLayout& handle ); ++ ++ EditLayout& operator=( const EditLayout& handle ); ++ ++ ~EditLayout(); ++ ++ EditLayout( Internal::EditLayout& internal ); ++ ++ explicit EditLayout( Dali::Internal::CustomActor* internal ); ++ ++ EditLayout DownCast( BaseHandle handle ); ++ ++ Internal::EditLayout& GetImpl( EditLayout& verticalLayout ); ++ ++private: ++}; ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_EDIT_LAYOUT_H__ diff --cc examples/text-field/text-field-example.cpp index 00000000,00000000..a9ea8cbb new file mode 100644 --- /dev/null +++ b/examples/text-field/text-field-example.cpp @@@ -1,0 -1,0 +1,122 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++/** ++ * @file text-field-example.cpp ++ * @brief Basic usage of TextField control ++ */ ++ ++// EXTERNAL INCLUDES ++#include ++#include ++ ++// INTERNAL INCLUDES ++#include "edit-layout.h" ++ ++using namespace Dali; ++using namespace Dali::Toolkit; ++ ++namespace ++{ ++ ++const float BORDER_WIDTH = 4.0f; ++ ++} // unnamed namespace ++ ++/** ++ * @brief The main class of the demo. ++ */ ++class TextFieldExample : public ConnectionTracker ++{ ++public: ++ ++ TextFieldExample( Application& application ) ++ : mApplication( application ) ++ { ++ // Connect to the Application's Init signal ++ mApplication.InitSignal().Connect( this, &TextFieldExample::Create ); ++ } ++ ++ ~TextFieldExample() ++ { ++ // Nothing to do here. ++ } ++ ++ /** ++ * One-time setup in response to Application InitSignal. ++ */ ++ void Create( Application& application ) ++ { ++ Stage stage = Stage::GetCurrent(); ++ ++ stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); ++ ++ Vector2 stageSize = stage.GetSize(); ++ ++ EditLayout layout = EditLayout::New(); ++ layout.SetParentOrigin( ParentOrigin::CENTER ); ++ layout.SetAnchorPoint( AnchorPoint::CENTER ); ++ layout.SetSize( stageSize.width - BORDER_WIDTH*2.0f, stageSize.height*0.2f ); ++ stage.Add( layout ); ++ ++ TextField field = TextField::New(); ++ field.SetParentOrigin( ParentOrigin::CENTER ); ++ field.SetBackgroundColor( Color::BLACK ); ++ layout.SetTopPanel( field ); ++ ++ field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); ++ ++ // TODO ++ //Property::Value fieldText = field.GetProperty( TextField::PROPERTY_TEXT ); ++ //std::cout << "Got text from field: " << fieldText.Get< std::string >() << std::endl; ++ } ++ ++ /** ++ * Main key event handler ++ */ ++ void OnKeyEvent(const KeyEvent& event) ++ { ++ if(event.state == KeyEvent::Down) ++ { ++ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) ++ { ++ mApplication.Quit(); ++ } ++ } ++ } ++ ++private: ++ ++ Application& mApplication; ++}; ++ ++void RunTest( Application& application ) ++{ ++ TextFieldExample test( application ); ++ ++ application.MainLoop(); ++} ++ ++/** Entry point for Linux & Tizen applications */ ++int main( int argc, char **argv ) ++{ ++ Application application = Application::New( &argc, &argv ); ++ ++ RunTest( application ); ++ ++ return 0; ++} diff --cc examples/text-label-multi-language/text-label-multi-language-example.cpp index 00000000,00000000..080251f6 new file mode 100644 --- /dev/null +++ b/examples/text-label-multi-language/text-label-multi-language-example.cpp @@@ -1,0 -1,0 +1,325 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++/** ++ * @file text-label-example.cpp ++ * @brief Basic usage of TextLabel control ++ */ ++ ++// INTERNAL INCLUDES ++#include "vertical-layout.h" ++ ++// EXTERNAL INCLUDES ++#include ++#include ++ ++using namespace Dali; ++using namespace Dali::Toolkit; ++ ++namespace ++{ ++ struct Language ++ { ++ std::string languageName; ++ std::string languageRomanName; ++ std::string text; ++ }; ++ ++ const Language LANGUAGES[] = { ++ { ++ "العَرَبِيةُ", ++ "(Arabic)", ++ "لإعادة ترتيب الشاشات، يجب تغيير نوع العرض إلى شبكة قابلة للتخصيص." ++ }, ++ { ++ "অসমীয়া লিপি", ++ "(Assamese)", ++ "পৃষ্ঠাসমূহ পুনঃব্যৱস্থিত কৰিবলৈ, আপুনি দৰ্শনৰ প্ৰকাৰ এটা অনুকূলনযোগ্য গ্ৰীডলৈ পৰিৱৰ্তন কৰাটো আৱশ্যক৷" ++ }, ++ { ++ "বাংলা", ++ "(Bengali)", ++ "তথ্য লোড করতে অক্ষম৷ পুনরায় চেষ্টা করতে ট্যাপ করুন৷" ++ }, ++ { ++ "English", ++ "(English)", ++ "A Quick Brown Fox Jumps Over The Lazy Dog" ++ }, ++ { ++ "Español", ++ "(Spanish)", ++ "No se puede añadir más aplicaciones. Se alcanzó la cantidad máxima." ++ }, ++ { ++ "فارسی", ++ "(Persian)", ++ "برای مرتب کردن مجدد صفحه‌ها، باید نوع نمایش را به یک نمای شبکه‌ای قابل تنظیم تغییر دهید." ++ }, ++ { ++ "Français", ++ "(French)", ++ "La nouvelle page sera composée des Dynamic Box S Planner, Tâches et S Memo" ++ }, ++ { ++ "ગુજરાતી લિપિ", ++ "(Gujarati)", ++ "પૃષ્ઠોને ફરીથી ગોઠવવા માટે, તમારે દૃશ્ય પ્રકારને કસ્ટમાઇઝેશન યોગ્ય ગ્રિડ પર બદલવાની જરૂર છે." ++ }, ++ { ++ "हिन्दी", ++ "(Hindi)", ++ "पेज पुनः व्यवस्थित करने के लिए, आपको दृश्य प्रकार को अनुकूलित करने योग्य ग्रिड में बदलना होगा।" ++ }, ++ { ++ "Bahasa Indonesia", ++ "(Indonesian)", ++ "Tidak dapat menambahkan aplikasi lagi. Jumlah maksimum aplikasi tercapai." ++ }, ++ { ++ "ខេមរភាសា", ++ "(Cambodian)", ++ "ដើម្បី​រៀបចំ​ទំព័រ​ឡើងវិញ អ្នក​ត្រូវ​ប្ដូរ​ប្រភេទ​បង្ហាញ​ទៅ​ក្រឡាចត្រង្គ​ដែល​អាច​ប្ដូរ​តាមបំណង។" ++ }, ++ { ++ "ಕನ್ನಡ ", ++ "(Kannada)", ++ "ಪುಟಗಳನ್ನು ಮರುವ್ಯವಸ್ಥಿತವಾಗಿ ಇರಿಸಲು, ನೀವು ವೀಕ್ಷಣೆ ವಿಧವನ್ನು ಗ್ರಾಹಕೀಕರಿಸಬಲ್ಲ ಗ್ರಿಡ್‌ಗೆ ಬದಲಾಯಿಸುವುದು ಅಗತ್ಯವಿದೆ." ++ }, ++ { ++ "한국어", ++ "(Korean)", ++ "페이지 순서를 변경하려면 보기 방식을 격자 보기(직접 설정)로 변경하세요." ++ }, ++ { ++ "ພາສາລາວ", ++ "(Lao)", ++ "ເພື່ອຈັດລຽງໜ້າຄືນ, ທ່ານຈໍາເປັນຕ້ອງປ່ຽນຊະນິດຂອງມຸມມອງໄປຫາຕາຕະລາງທີ່ກຳນົດເອງໄດ້." ++ }, ++ { ++ "മലയാളം", ++ "(Malayalam)", ++ "പേജുകൾ പുനഃക്രമീകരിക്കുന്നതിന്, ഇഷ്ടാനുസൃതമാക്കാവുന്ന ഗ്രിഡിലേക്ക് കാഴ്ചയുടെ തരം നിങ്ങൾ മാറ്റേണ്ടതുണ്ട്." ++ }, ++ { ++ "मराठी", ++ "(Marathi)", ++ "पृष्‍ठांची पुनर्रचना करा, आपण सानुकूलित करण्‍यायोग्‍य ग्रिडमध्‍ये व्‍ह्यू प्रकार बदलणे गरजेचे आहे." ++ }, ++ { ++ "Bahasa Melayu", ++ "(Malay)", ++ "Tidak boleh menambah aplikasi lagi. Bilangan maksimum aplikasi dicapai." ++ }, ++ { ++ "မြန်မာဘာသာ", ++ "(Burmese)", ++ "စာမ်က္ႏွာမ်ား ျပန္စီစဥ္ရန္ အျမင္ပံုစံကို စိတ္ၾကိဳက္လုပ္ႏိုင္ေသာ ဂရစ္ တစ္ခုသို႔ ေျပာင္းဖို႔လိုသည္။" ++ }, ++ { ++ "नेपाली", ++ "(Nepali)", ++ "थप अनुप्रयोगहरू थप्न सकिएन। अनुप्रयोगहरूको अधिकतम संख्या पुग्यो।" ++ }, ++ { ++ "ଓଡ଼ିଆ", ++ "(Oriya)", ++ "ପରବର୍ତ୍ତୀ ପୃଷ୍ଠା ଦେଖିବା ପାଇଁ ଦୁଇ ଆଙ୍ଗୁଠିରେ ସ୍ୱାଇପ୍ କରନ୍ତୁ।" ++ }, ++ { ++ "ਗੁਰਮੁਖੀ", ++ "(Punjabi)", ++ "ਇਹ ਫੋਲਡਰ ਅਤੇ ਇਸ ਵਿੱਚ ਸ਼ਾਮਲ ਸਾਰੇ ਆਈਟਮਾਂ ਨੂੰ ਮਿਟਾ ਦੇਵੇਗਾ।" ++ }, ++ { ++ "Português", ++ "(Portuguese)", ++ "Para reorganizar páginas, é necessário alterar o tipo de exibição para uma grade personalizável." ++ }, ++ { ++ "සිංහල", ++ "(Sinhala)", ++ "පිටු නැවත පෙළ ගැස්වීම සඳහා ඔබ විසින් දසුන් ප්‍රවර්ගය අභිමතීකෘත්‍ය ජාලයකට වෙනස් කළ යුතුය." ++ }, ++ { ++ "தமிழ்", ++ "(Tamil)", ++ "பக்கங்களை மறுஒழுங்குபடுத்தவென காட்சி வகையை தனிப்பயனாக்கத்தக்க கட்டமைப்பிற்கு மாற்ற வேண்டியுள்ளது." ++ }, ++ { ++ "తెలుగు", ++ "(Telugu)", ++ "మరిన్ని అప్లికేషన్‌లను జోడించడం సాధ్యం కాలేదు. గరిష్ట అప్లికేషన్‌ల సంఖ్యను చేరుకున్నాయి." ++ }, ++ { ++ "ภาษาไทย", ++ "(Thai)", ++ "คุณต้องเปลี่ยนชนิดการแสดง เป็นตารางที่กำหนดเองได้ เพื่อจัดหน้าใหม่" ++ }, ++ { ++ "Tagalog", ++ "(Tagalog)", ++ "Hindi makapagdagdag ng extra na linya dahil sa paghihigpit sa espasyo" ++ }, ++ { ++ "Türkçe", ++ "(Turkish)", ++ "Sayfaları yeniden düzenlemek için özelleştirilebilir kılavuzun görünüm tipini değiştirmeniz gerekir." ++ }, ++ { ++ "اُردُو‎", ++ "(Urdu)", ++ "صفحات کو دوبارہ ترتیب دینے کے لئے، آپ کو منظر کی قسم کو ایک حسب ضرورت گرڈ میں تبدیل کرنا ہوگا۔" ++ }, ++ { ++ "tiếng Việt", ++ "(Vietnamese)", ++ "Để sắp xếp lại các trang, bạn cần thay đổi kiểu xem sang dạng lưới tùy chỉnh." ++ }, ++ { ++ "漢語", ++ "(Chinese)", ++ "若要重新排列页面,您需要将视图类型更改为可自定义网格。" ++ }, ++ }; ++ ++ const unsigned int NUMBER_OF_LANGUAGES = 31u; ++} // namespace ++ ++/** ++ * @brief The main class of the demo. ++ */ ++class TextLabelMultiLanguageExample : public ConnectionTracker ++{ ++public: ++ ++ TextLabelMultiLanguageExample( Application& application ) ++ : mApplication( application ), ++ mLastPoint( 0.f ) ++ { ++ // Connect to the Application's Init signal ++ mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create ); ++ } ++ ++ ~TextLabelMultiLanguageExample() ++ { ++ // Nothing to do here. ++ } ++ ++ /** ++ * One-time setup in response to Application InitSignal. ++ */ ++ void Create( Application& application ) ++ { ++ Stage stage = Stage::GetCurrent(); ++ ++ stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent); ++ ++ mLayout = VerticalLayout::New(); ++ mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT ); ++ mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT ); ++ ++ stage.Add( mLayout ); ++ ++ for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index ) ++ { ++ const Language& language = LANGUAGES[index]; ++ ++ TextLabel label = TextLabel::New(); ++ label.SetParentOrigin( ParentOrigin::CENTER ); ++ ++ label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true ); ++ ++ const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text; ++ ++ label.SetProperty( TextLabel::PROPERTY_TEXT, text ); ++ mLayout.AddLabel( label ); ++ ++ mLayout.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent ); ++ } ++ ++ const Vector2& size = Stage::GetCurrent().GetSize(); ++ const float height = mLayout.GetHeightForWidth( size.width ); ++ mLayout.SetSize( Size( size.width, height ) ); ++ } ++ ++ bool OnTouchEvent( Actor actor, const TouchEvent& event ) ++ { ++ if( 1u == event.GetPointCount() ) ++ { ++ const TouchPoint::State state = event.GetPoint(0u).state; ++ ++ // Clamp to integer values; this is to reduce flicking due to pixel misalignment ++ const float localPoint = static_cast( static_cast( event.GetPoint( 0 ).local.y ) ); ++ ++ if( TouchPoint::Down == state ) ++ { ++ mLastPoint = localPoint; ++ mAnimation = Animation::New( 0.25f ); ++ } ++ else if( TouchPoint::Motion == state ) ++ { ++ if( mAnimation ) ++ { ++ mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); ++ mAnimation.Play(); ++ mLastPoint = localPoint; ++ } ++ } ++ } ++ ++ return true; ++ } ++ ++ /** ++ * Main key event handler ++ */ ++ void OnKeyEvent(const KeyEvent& event) ++ { ++ if(event.state == KeyEvent::Down) ++ { ++ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) ++ { ++ mApplication.Quit(); ++ } ++ } ++ } ++ ++private: ++ ++ Application& mApplication; ++ VerticalLayout mLayout; ++ Animation mAnimation; ++ float mLastPoint; ++}; ++ ++void RunTest( Application& application ) ++{ ++ TextLabelMultiLanguageExample test( application ); ++ ++ application.MainLoop(); ++} ++ ++/** Entry point for Linux & Tizen applications */ ++int main( int argc, char **argv ) ++{ ++ Application application = Application::New( &argc, &argv ); ++ ++ RunTest( application ); ++ ++ return 0; ++} diff --cc examples/text-label-multi-language/vertical-layout-impl.cpp index 00000000,00000000..e3b326a4 new file mode 100644 --- /dev/null +++ b/examples/text-label-multi-language/vertical-layout-impl.cpp @@@ -1,0 -1,0 +1,140 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "vertical-layout-impl.h" ++ ++// INTERNAL INCLUDES ++#include "vertical-layout.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++Toolkit::VerticalLayout VerticalLayout::New() ++{ ++ // Create the implementation, temporarily owned by this handle on stack ++ IntrusivePtr< VerticalLayout > impl = new VerticalLayout(); ++ ++ // Pass ownership to CustomActor handle ++ Toolkit::VerticalLayout handle( *impl ); ++ ++ // Second-phase init of the implementation ++ // This can only be done after the CustomActor connection has been made... ++ impl->Initialize(); ++ ++ return handle; ++} ++ ++VerticalLayout::VerticalLayout() ++: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) ++{ ++} ++ ++VerticalLayout::~VerticalLayout() ++{ ++} ++ ++void VerticalLayout::OnInitialize() ++{ ++} ++ ++Vector3 VerticalLayout::GetNaturalSize() ++{ ++ Vector3 size = Vector3::ZERO; ++ ++ CustomActor self = Self(); ++ for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) ++ { ++ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); ++ ++ if( label ) ++ { ++ Vector3 labelSize = label.GetNaturalSize(); ++ ++ size.width = ( labelSize.width > size.width ) ? labelSize.width : size.width; ++ size.height += labelSize.height; ++ } ++ } ++ ++ return size; ++} ++ ++float VerticalLayout::GetHeightForWidth( float width ) ++{ ++ float height = 0.f; ++ ++ CustomActor self = Self(); ++ for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) ++ { ++ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); ++ ++ if( label ) ++ { ++ height += label.GetHeightForWidth( width ); ++ } ++ } ++ ++ return height; ++} ++ ++float VerticalLayout::GetWidthForHeight( float height ) ++{ ++ return 0.f; ++} ++ ++void VerticalLayout::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) ++{ ++} ++ ++void VerticalLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) ++{ ++ CustomActor self = Self(); ++ ++ Vector3 position; ++ for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index ) ++ { ++ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) ); ++ ++ if( label ) ++ { ++ label.SetPosition( position ); ++ ++ position.height += label.GetHeightForWidth( size.width ); ++ } ++ ++ container.push_back( ActorSizePair( label, size ) ); ++ } ++} ++ ++void VerticalLayout::AddLabel( Toolkit::TextLabel label ) ++{ ++ Self().Add( label ); ++ ++ RelayoutRequest(); ++} ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-label-multi-language/vertical-layout-impl.h index 00000000,00000000..ecdfdd8c new file mode 100644 --- /dev/null +++ b/examples/text-label-multi-language/vertical-layout-impl.h @@@ -1,0 -1,0 +1,91 @@@ ++#ifndef __DALI_DEMO_VERTICAL_LAYOUT_IMPL_H__ ++#define __DALI_DEMO_VERTICAL_LAYOUT_IMPL_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// INTERNAL INCLUDES ++#include "vertical-layout.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++class VerticalLayout : public Control ++{ ++public: ++ /** ++ * @copydoc Dali::Toollkit::TextLabel::New() ++ */ ++ static Toolkit::VerticalLayout New(); ++ ++ VerticalLayout(); ++ ++ virtual ~VerticalLayout(); ++ ++ /** ++ * @copydoc Control::OnInitialize() ++ */ ++ virtual void OnInitialize(); ++ ++ // Size negotiation methods inherited from Internal::Control ++ ++ /** ++ * @copydoc Control::GetNaturalSize() ++ */ ++ virtual Vector3 GetNaturalSize(); ++ ++ /** ++ * @copydoc Control::GetHeightForWidth() ++ */ ++ virtual float GetHeightForWidth( float width ); ++ ++ /** ++ * @copydoc Control::GetWidthForHeight() ++ */ ++ virtual float GetWidthForHeight( float height ); ++ ++ /** ++ * @copydoc Control::OnFontChange() ++ */ ++ virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ); ++ ++ /** ++ * @copydoc Control::OnRelayout() ++ */ ++ virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); ++ ++ void AddLabel( Toolkit::TextLabel label ); ++ ++private: ++ // Undefined copy constructor and assignment operators ++ VerticalLayout(const VerticalLayout&); ++ VerticalLayout& operator=(const VerticalLayout& rhs); ++}; ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_VERTICAL_LAYOUT_IMPL_H__ diff --cc examples/text-label-multi-language/vertical-layout.cpp index 00000000,00000000..80466324 new file mode 100644 --- /dev/null +++ b/examples/text-label-multi-language/vertical-layout.cpp @@@ -1,0 -1,0 +1,88 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "vertical-layout.h" ++ ++// INTERNAL INCLUDES ++#include "vertical-layout-impl.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++VerticalLayout VerticalLayout::New() ++{ ++ return Internal::VerticalLayout::New(); ++} ++ ++VerticalLayout::VerticalLayout() ++{ ++} ++ ++VerticalLayout::VerticalLayout( const VerticalLayout& handle ) ++: Control( handle ) ++{ ++} ++ ++VerticalLayout& VerticalLayout::operator=( const VerticalLayout& handle ) ++{ ++ if( &handle != this ) ++ { ++ Control::operator=( handle ); ++ } ++ return *this; ++} ++ ++VerticalLayout VerticalLayout::DownCast( BaseHandle handle ) ++{ ++ return Control::DownCast( handle ); ++} ++ ++VerticalLayout::~VerticalLayout() ++{ ++} ++ ++VerticalLayout::VerticalLayout( Internal::VerticalLayout& internal ) ++: Control( internal ) ++{ ++} ++ ++VerticalLayout::VerticalLayout( Dali::Internal::CustomActor* internal ) ++: Control( internal ) ++{ ++} ++ ++void VerticalLayout::AddLabel( TextLabel label ) ++{ ++ GetImpl( *this ).AddLabel( label ); ++} ++ ++Internal::VerticalLayout& VerticalLayout::GetImpl( VerticalLayout& verticalLayout ) ++{ ++ DALI_ASSERT_ALWAYS( verticalLayout ); ++ ++ Dali::RefObject& handle = verticalLayout.GetImplementation(); ++ ++ return static_cast(handle); ++} ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-label-multi-language/vertical-layout.h index 00000000,00000000..1f8b176f new file mode 100644 --- /dev/null +++ b/examples/text-label-multi-language/vertical-layout.h @@@ -1,0 -1,0 +1,65 @@@ ++#ifndef __DALI_DEMO_VERTICAL_LAYOUT_H__ ++#define __DALI_DEMO_VERTICAL_LAYOUT_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// EXTERNAL INCLUDES ++#include ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++class VerticalLayout; ++} // namespace Internal ++ ++class VerticalLayout : public Toolkit::Control ++{ ++public: ++ static VerticalLayout New(); ++ ++ VerticalLayout(); ++ ++ VerticalLayout( const VerticalLayout& handle ); ++ ++ VerticalLayout& operator=( const VerticalLayout& handle ); ++ ++ ~VerticalLayout(); ++ ++ VerticalLayout( Internal::VerticalLayout& internal ); ++ ++ explicit VerticalLayout( Dali::Internal::CustomActor* internal ); ++ ++ VerticalLayout DownCast( BaseHandle handle ); ++ ++ void AddLabel( TextLabel label ); ++ ++ Internal::VerticalLayout& GetImpl( VerticalLayout& verticalLayout ); ++ ++private: ++}; ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_VERTICAL_LAYOUT_H__ diff --cc examples/text-label/center-layout-impl.cpp index 00000000,00000000..e08db35b new file mode 100644 --- /dev/null +++ b/examples/text-label/center-layout-impl.cpp @@@ -1,0 -1,0 +1,132 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "center-layout-impl.h" ++ ++// INTERNAL INCLUDES ++#include "center-layout.h" ++ ++namespace ++{ ++ int ConvertToEven(int value) ++ { ++ return (value % 2 == 0) ? value : (value + 1); ++ } ++} ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++Toolkit::CenterLayout CenterLayout::New() ++{ ++ // Create the implementation, temporarily owned by this handle on stack ++ IntrusivePtr< CenterLayout > impl = new CenterLayout(); ++ ++ // Pass ownership to CustomActor handle ++ Toolkit::CenterLayout handle( *impl ); ++ ++ // Second-phase init of the implementation ++ // This can only be done after the CustomActor connection has been made... ++ impl->Initialize(); ++ ++ return handle; ++} ++ ++CenterLayout::CenterLayout() ++: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) ++{ ++} ++ ++CenterLayout::~CenterLayout() ++{ ++} ++ ++void CenterLayout::OnInitialize() ++{ ++ CustomActor self = Self(); ++ ++ // Move background behind text label ++ Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Vector4(0.1f,0.1f,0.1f,1.0f) ); ++ self.GetChildAt(0).SetZ(-1.0f); ++ ++ Stage stage = Stage::GetCurrent(); ++ Vector2 stageSize = stage.GetSize(); ++ ++ // Resize the center layout when the corner is grabbed ++ mGrabCorner = CreateSolidColorActor( Color::GREEN ); ++ mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); ++ mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); ++ mGrabCorner.SetSize( stageSize.width*0.1f, stageSize.width*0.1f ); ++ mGrabCorner.SetZ(1.0f); ++ self.Add( mGrabCorner ); ++ ++ mPanGestureDetector = PanGestureDetector::New(); ++ mPanGestureDetector.Attach( mGrabCorner ); ++ mPanGestureDetector.DetectedSignal().Connect( this, &CenterLayout::OnPan ); ++} ++ ++void CenterLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) ++{ ++ CustomActor self = Self(); ++ ++ if( mLayoutSize.x <= 0.0f ) ++ { ++ mLayoutSize = size; ++ } ++ ++ for( unsigned int i=0; i(mLayoutSize.x)), ++ ConvertToEven(static_cast(mLayoutSize.y)) ); ++ ++ Self().SetSize( clampedSize ); ++ ++ RelayoutRequest(); ++} ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-label/center-layout-impl.h index 00000000,00000000..850b9b86 new file mode 100644 --- /dev/null +++ b/examples/text-label/center-layout-impl.h @@@ -1,0 -1,0 +1,80 @@@ ++#ifndef __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ ++#define __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// INTERNAL INCLUDES ++#include "center-layout.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++ ++class CenterLayout : public Control ++{ ++public: ++ /** ++ * @copydoc Dali::Toollkit::TextLabel::New() ++ */ ++ static Toolkit::CenterLayout New(); ++ ++ CenterLayout(); ++ ++ virtual ~CenterLayout(); ++ ++ /** ++ * @copydoc Control::OnInitialize() ++ */ ++ virtual void OnInitialize(); ++ ++ // Size negotiation methods inherited from Internal::Control ++ ++ /** ++ * @copydoc Control::OnRelayout() ++ */ ++ virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); ++ ++private: ++ ++ void OnPan( Actor actor, const PanGesture& gesture ); ++ ++ // Undefined copy constructor and assignment operators ++ CenterLayout(const CenterLayout&); ++ CenterLayout& operator=(const CenterLayout& rhs); ++ ++private: ++ ++ Vector3 mLayoutSize; ++ ++ Actor mGrabCorner; ++ ++ PanGestureDetector mPanGestureDetector; ++}; ++ ++} // namespace Internal ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ diff --cc examples/text-label/center-layout.cpp index 00000000,00000000..e49be0ea new file mode 100644 --- /dev/null +++ b/examples/text-label/center-layout.cpp @@@ -1,0 -1,0 +1,83 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// CLASS HEADER ++#include "center-layout.h" ++ ++// INTERNAL INCLUDES ++#include "center-layout-impl.h" ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++CenterLayout CenterLayout::New() ++{ ++ return Internal::CenterLayout::New(); ++} ++ ++CenterLayout::CenterLayout() ++{ ++} ++ ++CenterLayout::CenterLayout( const CenterLayout& handle ) ++: Control( handle ) ++{ ++} ++ ++CenterLayout& CenterLayout::operator=( const CenterLayout& handle ) ++{ ++ if( &handle != this ) ++ { ++ Control::operator=( handle ); ++ } ++ return *this; ++} ++ ++CenterLayout CenterLayout::DownCast( BaseHandle handle ) ++{ ++ return Control::DownCast( handle ); ++} ++ ++CenterLayout::~CenterLayout() ++{ ++} ++ ++CenterLayout::CenterLayout( Internal::CenterLayout& internal ) ++: Control( internal ) ++{ ++} ++ ++CenterLayout::CenterLayout( Dali::Internal::CustomActor* internal ) ++: Control( internal ) ++{ ++} ++ ++Internal::CenterLayout& CenterLayout::GetImpl( CenterLayout& verticalLayout ) ++{ ++ DALI_ASSERT_ALWAYS( verticalLayout ); ++ ++ Dali::RefObject& handle = verticalLayout.GetImplementation(); ++ ++ return static_cast(handle); ++} ++ ++} // namespace Toolkit ++ ++} // namespace Dali diff --cc examples/text-label/center-layout.h index 00000000,00000000..2807fccb new file mode 100644 --- /dev/null +++ b/examples/text-label/center-layout.h @@@ -1,0 -1,0 +1,63 @@@ ++#ifndef __DALI_DEMO_CENTER_LAYOUT_H__ ++#define __DALI_DEMO_CENTER_LAYOUT_H__ ++ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++// EXTERNAL INCLUDES ++#include ++ ++namespace Dali ++{ ++ ++namespace Toolkit ++{ ++ ++namespace Internal ++{ ++class CenterLayout; ++} // namespace Internal ++ ++class CenterLayout : public Toolkit::Control ++{ ++public: ++ static CenterLayout New(); ++ ++ CenterLayout(); ++ ++ CenterLayout( const CenterLayout& handle ); ++ ++ CenterLayout& operator=( const CenterLayout& handle ); ++ ++ ~CenterLayout(); ++ ++ CenterLayout( Internal::CenterLayout& internal ); ++ ++ explicit CenterLayout( Dali::Internal::CustomActor* internal ); ++ ++ CenterLayout DownCast( BaseHandle handle ); ++ ++ Internal::CenterLayout& GetImpl( CenterLayout& verticalLayout ); ++ ++private: ++}; ++ ++} // namespace Toolkit ++ ++} // namespace Dali ++ ++#endif // __DALI_DEMO_CENTER_LAYOUT_H__ diff --cc examples/text-label/text-label-example.cpp index 00000000,00000000..7c18de1e new file mode 100644 --- /dev/null +++ b/examples/text-label/text-label-example.cpp @@@ -1,0 -1,0 +1,114 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++/** ++ * @file text-label-example.cpp ++ * @brief Basic usage of TextLabel control ++ */ ++ ++// EXTERNAL INCLUDES ++#include ++#include ++ ++// INTERNAL INCLUDES ++#include "center-layout.h" ++ ++using namespace Dali; ++using namespace Dali::Toolkit; ++ ++/** ++ * @brief The main class of the demo. ++ */ ++class TextLabelExample : public ConnectionTracker ++{ ++public: ++ ++ TextLabelExample( Application& application ) ++ : mApplication( application ) ++ { ++ // Connect to the Application's Init signal ++ mApplication.InitSignal().Connect( this, &TextLabelExample::Create ); ++ } ++ ++ ~TextLabelExample() ++ { ++ // Nothing to do here. ++ } ++ ++ /** ++ * One-time setup in response to Application InitSignal. ++ */ ++ void Create( Application& application ) ++ { ++ Stage stage = Stage::GetCurrent(); ++ ++ stage.SetBackgroundColor( Color::BLUE ); ++ stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent); ++ Vector2 stageSize = stage.GetSize(); ++ ++ CenterLayout centerLayout = CenterLayout::New(); ++ centerLayout.SetParentOrigin( ParentOrigin::CENTER ); ++ centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f ); ++ stage.Add( centerLayout ); ++ ++ TextLabel label = TextLabel::New(); ++ label.SetBackgroundColor( Color::BLACK ); ++ centerLayout.Add( label ); ++ ++ label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true ); ++ label.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); ++ ++ // TODO ++ //Property::Value labelText = label.GetProperty( TextLabel::PROPERTY_TEXT ); ++ //std::cout << "Got text from label: " << labelText.Get< std::string >() << std::endl; ++ } ++ ++ /** ++ * Main key event handler ++ */ ++ void OnKeyEvent(const KeyEvent& event) ++ { ++ if(event.state == KeyEvent::Down) ++ { ++ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) ++ { ++ mApplication.Quit(); ++ } ++ } ++ } ++ ++private: ++ ++ Application& mApplication; ++}; ++ ++void RunTest( Application& application ) ++{ ++ TextLabelExample test( application ); ++ ++ application.MainLoop(); ++} ++ ++/** Entry point for Linux & Tizen applications */ ++int main( int argc, char **argv ) ++{ ++ Application application = Application::New( &argc, &argv ); ++ ++ RunTest( application ); ++ ++ return 0; ++} diff --cc shared/dali-demo-strings.h index 00000000,00000000..a01d1705 new file mode 100644 --- /dev/null +++ b/shared/dali-demo-strings.h @@@ -1,0 -1,0 +1,57 @@@ ++/* ++ * Copyright (c) 2015 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. ++ * ++ */ ++ ++/* This header file includes all multi language strings which need display */ ++#ifndef __DALI_DEMO_STRINGS_H__ ++#define __DALI_DEMO_STRINGS_H__ ++ ++#include ++ ++#ifdef __cplusplus ++extern "C" ++{ ++#endif // __cplusplus ++ ++#define DALI_DEMO_DOMAIN_LOCAL "dali-demo" ++ ++#define DALI_DEMO_STR_EMPTY _("") ++ ++#define DALI_DEMO_STR_TEST dgettext(DALI_DEMO_DOMAIN_LOCAL, "IDS_ST_HEADER_PRIVACY") ++ ++#define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") ++#define DALI_DEMO_STR_TITLE_BLOCKS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS") ++#define DALI_DEMO_STR_TITLE_CLUSTER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLUSTER") ++#define DALI_DEMO_STR_TITLE_CUBE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CUBE_TRANSITION") ++#define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION") ++#define DALI_DEMO_STR_TITLE_ITEM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ITEM_VIEW") ++#define DALI_DEMO_STR_TITLE_MAGNIFIER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MAGNIFIER") ++#define DALI_DEMO_STR_TITLE_MOTION_BLUR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_BLUR") ++#define DALI_DEMO_STR_TITLE_MOTION_STRETCH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_STRETCH") ++#define DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW") ++#define DALI_DEMO_STR_TITLE_RADIAL_MENU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RADIAL_MENU") ++#define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") ++#define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") ++#define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS") ++#define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") ++#define DALI_DEMO_STR_TITLE_IMAGE_SCALING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_SCALING") ++#define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") ++ ++#ifdef __cplusplus ++} ++#endif // __cplusplus ++ ++#endif // __DALI_DEMO_STRINGS_H__ diff --cc shared/view.h index 00000000,584a278a..e13be634 mode 000000,100644..100644 --- a/shared/view.h +++ b/shared/view.h @@@ -1,0 -1,191 +1,146 @@@ + #ifndef __DALI_DEMO_HELPER_VIEW_H__ + #define __DALI_DEMO_HELPER_VIEW_H__ + + /* + * 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 + + namespace DemoHelper + { + + /** + * Provide a style for the view and its tool bar. + */ + struct ViewStyle + { + ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding ) + : mToolBarButtonPercentage( toolBarButtonPercentage ), + mToolBarTitlePercentage( toolBarTitlePercentage ), + mToolBarHeight( toolBarHeight ), + mToolBarPadding( toolBarPadding ) + {} + + float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width. + float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width. + float mToolBarHeight; ///< The tool bar height (in pixels). + float mToolBarPadding; ///< The tool bar padding (in pixels).. + }; + + const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f ); + + const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue"); + const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular"); -const Dali::PointSize DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f ); -const Dali::TextStyle::Weight DEFAULT_TEXT_STYLE_WEIGHT(Dali::TextStyle::EXTRALIGHT); + const Dali::Vector4 DEFAULT_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f); + + const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f); + const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f); + -static Dali::TextStyle defaultTextStyle; -static bool textStyleSet=false; - + float ScalePointSize(int pointSize) + { + Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi(); + float meanDpi = (dpi.height + dpi.width) * 0.5f; + return pointSize * 220.0f / meanDpi; // 220 is the default horizontal DPI defined in adaptor Application + } + -Dali::TextStyle& GetDefaultTextStyle() -{ - if(!textStyleSet) - { - defaultTextStyle.SetFontName(DEFAULT_TEXT_STYLE_FONT_FAMILY); - defaultTextStyle.SetFontStyle(DEFAULT_TEXT_STYLE_FONT_STYLE); - defaultTextStyle.SetFontPointSize(Dali::PointSize(ScalePointSize(DEFAULT_TEXT_STYLE_POINT_SIZE))); - defaultTextStyle.SetWeight(DEFAULT_TEXT_STYLE_WEIGHT); - defaultTextStyle.SetTextColor(DEFAULT_TEXT_STYLE_COLOR); - textStyleSet = true; - } - - return defaultTextStyle; -} - + Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, + const std::string& toolbarImagePath, + const std::string& title, - const ViewStyle& style, - const Dali::TextStyle& textStyle ) ++ const ViewStyle& style ) + { + Dali::Layer toolBarLayer = Dali::Layer::New(); + toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); + toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); + toolBarLayer.ApplyConstraint( Dali::Constraint::New( Dali::Actor::Property::Size, Dali::ParentSource( Dali::Actor::Property::Size ), Dali::SourceWidthFixedHeight( style.mToolBarHeight ) ) ); + toolBarLayer.SetSize( 0.0f, style.mToolBarHeight ); + + // Raise tool bar layer to the top. + toolBarLayer.RaiseToTop(); + + // Tool bar + Dali::Image image = Dali::ResourceImage::New( toolbarImagePath ); + Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image ); + toolBar = Dali::Toolkit::ToolBar::New(); + toolBar.SetBackground( toolBarBackground ); + toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); + toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); + toolBar.SetSize( 0.0f, style.mToolBarHeight ); + toolBar.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT ); + toolBarBackground.SetSortModifier(1.0f); + + // Add the tool bar to the too bar layer. + toolBarLayer.Add( toolBar ); + - Dali::Font font = Dali::Font::New(); - + // Tool bar text. + if( !title.empty() ) + { - Dali::Toolkit::TextView titleActor = Dali::Toolkit::TextView::New(); - titleActor.SetName( "ToolbarTitle" ); - titleActor.SetText( title ); - titleActor.SetSize( font.MeasureText( title ) ); - titleActor.SetStyleToCurrentText(textStyle); - - // Add title to the tool bar. - const float padding( style.mToolBarPadding ); - toolBar.AddControl( titleActor, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) ); ++ // TODO + } + + return toolBarLayer; + } + + Dali::Layer CreateView( Dali::Application& application, + Dali::Toolkit::View& view, + Dali::Toolkit::ToolBar& toolBar, + const std::string& backgroundImagePath, + const std::string& toolbarImagePath, + const std::string& title, - const ViewStyle& style, - const Dali::TextStyle& textStyle ) ++ const ViewStyle& style = DEFAULT_VIEW_STYLE ) + { + Dali::Stage stage = Dali::Stage::GetCurrent(); + + // Create default View. + view = Dali::Toolkit::View::New(); + + // Add the view to the stage before setting the background. + stage.Add( view ); + + // Set background image. + if ( ! backgroundImagePath.empty() ) + { + Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath ); + Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage ); + view.SetBackground( backgroundImageActor ); + } + + // FIXME + // Connects the orientation signal with the View::OrientationChanged method. + //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged ); + + // Create default ToolBar - Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style, textStyle ); ++ Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style ); + + // Add tool bar layer to the view. + view.AddContentLayer( toolBarLayer ); + + + + // Create a content layer. + Dali::Layer contentLayer = Dali::Layer::New(); + contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER ); + contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER ); + contentLayer.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT ); + view.AddContentLayer( contentLayer ); + contentLayer.LowerBelow( toolBarLayer ); + + return contentLayer; + } + -Dali::Layer CreateView( Dali::Application& application, - Dali::Toolkit::View& view, - Dali::Toolkit::ToolBar& toolBar, - const std::string& backgroundImagePath, - const std::string& toolbarImagePath, - const std::string& title, - const ViewStyle& style = DEFAULT_VIEW_STYLE ) -{ - return CreateView( application, view, toolBar, backgroundImagePath, toolbarImagePath, title, style, - GetDefaultTextStyle() ); -} - - + } // DemoHelper + + #endif // __DALI_DEMO_HELPER_VIEW_H__