X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fimage-view-svg%2Fimage-view-svg-example.cpp;h=13ba31db039f297a4efc97e0858208e129c7a90f;hb=57e0c2288d54f4707076e14e4d49ca175ada7af1;hp=613ecb752c49939a7a5046f8c6ef8a6a779fef35;hpb=fe51b34a968be11d80b032030cf1a20ff8bf7e85;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/image-view-svg/image-view-svg-example.cpp b/examples/image-view-svg/image-view-svg-example.cpp index 613ecb7..13ba31d 100644 --- a/examples/image-view-svg/image-view-svg-example.cpp +++ b/examples/image-view-svg/image-view-svg-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -23,6 +23,7 @@ using namespace Dali; namespace { +const float MIN_SCALE = 0.6f; const float MAX_SCALE = 6.f; const char* SVG_IMAGES[] = @@ -37,9 +38,10 @@ const char* SVG_IMAGES[] = DEMO_IMAGE_DIR "Kid1.svg" }; const unsigned int NUM_SVG_IMAGES( sizeof( SVG_IMAGES ) / sizeof( SVG_IMAGES[0] ) ); -} +const unsigned int NUM_IMAGES_DISPLAYED = 4u; +} // unnamed namespace -// This example shows how to display svg images with ImageView +// This example shows how to display svg images with ImageView. // class ImageSvgController : public ConnectionTracker { @@ -48,7 +50,6 @@ public: ImageSvgController( Application& application ) : mApplication( application ), mScale( 1.f ), - mScaleAtPinchStart( 1.0f ), mIndex( 0 ) { // Connect to the Application's Init signal @@ -87,7 +88,6 @@ public: changeButton.SetParentOrigin( ParentOrigin::TOP_RIGHT ); stage.Add( changeButton ); changeButton.ClickedSignal().Connect( this, &ImageSvgController::OnChangeButtonClicked ); - changeButton.SetProperty( DevelActor::Property::SIBLING_ORDER, 1 ); // Push button, for resetting the actor size and position Toolkit::PushButton resetButton = Toolkit::PushButton::New(); @@ -96,10 +96,9 @@ public: resetButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); stage.Add( resetButton ); resetButton.ClickedSignal().Connect( this, &ImageSvgController::OnResetButtonClicked ); - resetButton.SetProperty( DevelActor::Property::SIBLING_ORDER, 1 ); // Create and put imageViews to stage - for( unsigned int i=0; i<4u; i++) + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) { mSvgActor[i] = Toolkit::ImageView::New(SVG_IMAGES[mIndex+i]); mSvgActor[i].SetSize( mActorSize ); @@ -124,13 +123,16 @@ public: mPinchGestureDetector = PinchGestureDetector::New(); mPinchGestureDetector.Attach( mStageBackground); mPinchGestureDetector.DetectedSignal().Connect(this, &ImageSvgController::OnPinch); + + changeButton.RaiseToTop(); + resetButton.RaiseToTop(); } // Callback of push button, for changing image set bool OnChangeButtonClicked( Toolkit::Button button ) { - mIndex = (mIndex+4) % NUM_SVG_IMAGES; - for( unsigned int i=0; i<4u; i++) + mIndex = ( mIndex + NUM_IMAGES_DISPLAYED ) % NUM_SVG_IMAGES; + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) { mSvgActor[i].SetImage(SVG_IMAGES[mIndex+i]); } @@ -141,7 +143,7 @@ public: // Callback of push button, for resetting image size and position bool OnResetButtonClicked( Toolkit::Button button ) { - for( unsigned int i=0; i<4u; i++) + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED ; i++ ) { mSvgActor[i].SetSize(mActorSize); mSvgActor[i].SetPosition( Vector3::ZERO ); @@ -156,7 +158,7 @@ public: { if( gesture.state == Gesture::Continuing ) { - for( unsigned int i=0; i<4u; i++) + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) { mSvgActor[i].TranslateBy(Vector3(gesture.displacement)); } @@ -166,18 +168,42 @@ public: // Callback of pinch gesture, for resizing the actors void OnPinch(Actor actor, const PinchGesture& gesture) { - if (gesture.state == Gesture::Started) - { - mScaleAtPinchStart = mScale; - } - if( gesture.state == Gesture::Finished ) + switch( gesture.state ) { - mScale = mScaleAtPinchStart * gesture.scale; - mScale = mScale > MAX_SCALE ? MAX_SCALE : mScale; - for( unsigned int i=0; i<4u; i++) + // Only scale the image when we start or continue pinching + + case Gesture::Started: + case Gesture::Continuing: + { + float scale = std::max( gesture.scale, MIN_SCALE / mScale ); + scale = std::min( MAX_SCALE / mScale, scale ); + + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + { + mSvgActor[i].SetScale( scale ); + } + break; + } + + case Gesture::Finished: { - mSvgActor[i].SetSize( mActorSize * mScale); + // Resize the image when pinching is complete, this will rasterize the SVG to the new size + + mScale = mScale * gesture.scale; + mScale = mScale > MAX_SCALE ? MAX_SCALE : mScale; + mScale = mScale < MIN_SCALE ? MIN_SCALE : mScale; + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + { + mSvgActor[i].SetSize( mActorSize * mScale ); + mSvgActor[i].SetScale( 1.0f ); + } + break; } + + case Gesture::Cancelled: + case Gesture::Clear: + case Gesture::Possible: + break; } } @@ -197,10 +223,13 @@ public: const char* keyName = event.keyPressedName.c_str(); if( strcmp(keyName, "Left") == 0 ) { - mScale /= 1.1f; - for( unsigned int i=0; i<4u; i++) + if( mScale > MIN_SCALE ) + { + mScale /= 1.1f; + } + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) { - mSvgActor[i].SetSize( mActorSize * mScale); + mSvgActor[i].SetSize( mActorSize * mScale ); } } else if( strcmp(keyName, "Right") == 0 ) @@ -209,9 +238,9 @@ public: { mScale *= 1.1f; } - for( unsigned int i=0; i<4u; i++) + for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) { - mSvgActor[i].SetSize( mActorSize * mScale); + mSvgActor[i].SetSize( mActorSize * mScale ); } } } @@ -227,24 +256,13 @@ private: Toolkit::ImageView mSvgActor[4]; Vector2 mActorSize; float mScale; - float mScaleAtPinchStart; unsigned int mIndex; }; -void RunTest( Application& application ) -{ - ImageSvgController test( application ); - - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications -// int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); - - RunTest( application ); - + ImageSvgController test( application ); + application.MainLoop(); return 0; }