X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fimage-scaling-and-filtering%2Fimage-scaling-and-filtering-example.cpp;h=c6941b47f842217fa0cfffa02bdc8bd9a01f96b4;hb=44f2524da6209b12ce1ea7e62bb3d1e79258dc32;hp=b5d240704a536e2f760d9a884adb2f61d4b524fa;hpb=c7e19c0123196e055968964a863a3d4c26a14555;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp index b5d2407..c6941b4 100644 --- a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -18,6 +18,7 @@ #include #include #include +#include #include "shared/view.h" #include @@ -45,9 +46,8 @@ const char* const SAMPLING_BUTTON_ID = "SAMPLING_BUTTON"; const char* const FITTING_BUTTON_TEXT = "Fitting"; const char* const SAMPLING_BUTTON_TEXT = "Sampling"; -const char* const STYLE_LABEL_TEXT = "grouplabel"; -const char* const STYLE_BUTTON_TEXT = "buttonlabel"; - +const char* const STYLE_LABEL_TEXT = "ImageScalingGroupLabel"; +const char* const STYLE_BUTTON_TEXT = "ImageScalingButton"; const char* IMAGE_PATHS[] = { @@ -153,6 +153,7 @@ public: ImageScalingAndFilteringController( Application& application ) : mApplication( application ), + mLastPinchScale( 1.0f ), mImageStageScale( 0.5f, 0.5f ), mCurrentPath( 0 ), mFittingMode( FittingMode::FIT_WIDTH ), @@ -175,14 +176,17 @@ public: // Get a handle to the stage Stage stage = Stage::GetCurrent(); + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + // Background image: Dali::Property::Map backgroundImage; - backgroundImage.Insert( "rendererType", "image" ); - backgroundImage.Insert( "imageUrl", BACKGROUND_IMAGE ); - backgroundImage.Insert( "imageDesiredWidth", stage.GetSize().width ); - backgroundImage.Insert( "imageDesiredHeight", stage.GetSize().height ); - backgroundImage.Insert( "imageFittingMode", "scaleToFill" ); - backgroundImage.Insert( "imageSamplingMode", "boxThenNearest" ); + backgroundImage.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); + backgroundImage.Insert( Toolkit::ImageVisual::Property::URL, BACKGROUND_IMAGE ); + backgroundImage.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, stage.GetSize().width ); + backgroundImage.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, stage.GetSize().height ); + backgroundImage.Insert( Toolkit::ImageVisual::Property::FITTING_MODE, FittingMode::SCALE_TO_FILL ); + backgroundImage.Insert( Toolkit::ImageVisual::Property::SAMPLING_MODE, SamplingMode::BOX_THEN_NEAREST ); Toolkit::ImageView background = Toolkit::ImageView::New(); background.SetProperty( Toolkit::ImageView::Property::IMAGE, backgroundImage ); @@ -284,8 +288,7 @@ public: // Back and next image buttons in corners of stage: unsigned int playWidth = std::min( stage.GetSize().x * (1 / 5.0f), 58.0f ); - Image playImage = ResourceImage::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ), FittingMode::SHRINK_TO_FIT, SamplingMode::BOX_THEN_LINEAR ); - Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( playImage ); + Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); // Last image button: imagePrevious.SetAnchorPoint( AnchorPoint::TOP_LEFT ); @@ -295,17 +298,17 @@ public: imagePrevious.SetOpacity( 0.6f ); controlsLayer.Add( imagePrevious ); imagePrevious.SetName( PREVIOUS_BUTTON_ID ); - imagePrevious.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + imagePrevious.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); // Next image button: - Toolkit::ImageView imageNext = Toolkit::ImageView::New( playImage ); + Toolkit::ImageView imageNext = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); imageNext.SetY( playWidth * 0.5f ); imageNext.SetX( stage.GetSize().x - playWidth * 0.5f ); imageNext.SetOpacity( 0.6f ); controlsLayer.Add( imageNext ); imageNext.SetName( NEXT_BUTTON_ID ); - imageNext.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + imageNext.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); // Buttons to popup selectors for fitting and sampling modes: @@ -334,7 +337,7 @@ public: fittingModeGroup.SetFitHeight( 1 ); TextLabel label = TextLabel::New( "Image fitting mode:" ); - label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT ); + label.SetStyleName( STYLE_LABEL_TEXT ); fittingModeGroup.Add( label ); Toolkit::PushButton button = CreateButton( FITTING_BUTTON_ID, StringFromScalingMode( mFittingMode ) ); @@ -355,7 +358,7 @@ public: samplingModeGroup.SetFitHeight( 1 ); TextLabel label = TextLabel::New( "Image sampling mode:" ); - label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT ); + label.SetStyleName( STYLE_LABEL_TEXT ); samplingModeGroup.Add( label ); Toolkit::PushButton button = CreateButton( SAMPLING_BUTTON_ID, StringFromFilterMode( mSamplingMode ) ); @@ -369,9 +372,9 @@ public: Toolkit::PushButton CreateButton( const char * id, const char * label ) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + button.SetStyleName( STYLE_BUTTON_TEXT ); button.SetName( id ); - button.SetLabelText( label ); + button.SetProperty( Toolkit::Button::Property::LABEL, label ); button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); @@ -398,7 +401,7 @@ public: { Toolkit::PushButton button = Toolkit::PushButton::New(); button.SetName( id ); - button.SetLabelText( id ); + button.SetProperty( Toolkit::Button::Property::LABEL, id ); button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); button.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); @@ -487,7 +490,7 @@ public: if( button.GetName() == modeName ) { mFittingMode = mode; - mFittingModeButton.SetLabelText( modeName ); + mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); ResizeImage(); mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); @@ -502,7 +505,7 @@ public: if( button.GetName() == modeName ) { mSamplingMode = mode; - mSamplingModeButton.SetLabelText( modeName ); + mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); ResizeImage(); mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); @@ -520,29 +523,13 @@ public: } } - void OnImageLoaded( ResourceImage image ) - { - DALI_ASSERT_DEBUG( image == mNextImage ); - mImageView.SetImage( image ); - mImageView.SetSize( Size( image.GetWidth(), image.GetHeight() ) ); - mImageLoading = false; - - // We have finished loading, if a resize had occured during the load, trigger another load now. - if( mQueuedImageLoad ) - { - mQueuedImageLoad = false; - LoadImage(); - } - } - - bool OnControlTouched( Actor actor, const TouchEvent& event ) + bool OnControlTouched( Actor actor, const TouchData& event ) { if(event.GetPointCount() > 0) { - const TouchPoint& point = event.GetPoint(0); - switch(point.state) + switch( event.GetState( 0 ) ) { - case TouchPoint::Up: + case PointState::UP: { const std::string & name = actor.GetName(); if( name == NEXT_BUTTON_ID ) @@ -660,13 +647,13 @@ public: else if ( event.keyPressedName == "f" ) { mSamplingMode = NextFilterMode( mSamplingMode ); - mSamplingModeButton.SetLabelText( StringFromFilterMode( mSamplingMode ) ); + mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromFilterMode( mSamplingMode ) ); } // Cycle filter and scaling modes: else if ( event.keyPressedName == "s" ) { mFittingMode = NextScalingMode( mFittingMode ); - mFittingModeButton.SetLabelText( StringFromScalingMode( mFittingMode ) ); + mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromScalingMode( mFittingMode ) ); } else { @@ -686,21 +673,17 @@ private: const char * const path = IMAGE_PATHS[ mCurrentPath ]; Stage stage = Stage::GetCurrent(); Size imageSize = stage.GetSize() * mImageStageScale; - const ImageDimensions imageSizeInt = ImageDimensions::FromFloatArray( &imageSize.x ); + mImageView.SetSize( imageSize ); - ResourceImage image = ResourceImage::New( path, imageSizeInt, mFittingMode, mSamplingMode ); + Property::Map map; + map[Toolkit::ImageVisual::Property::URL] = path; + map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = imageSize.x; + map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = imageSize.y; + map[Toolkit::ImageVisual::Property::FITTING_MODE] = mFittingMode; + map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = mSamplingMode; - // If the image was cached, the load has already occured, bypass hooking the signal. - if( image.GetLoadingState() ) - { - OnImageLoaded( image ); - } - else - { - image.LoadingFinishedSignal().Connect( this, &ImageScalingAndFilteringController::OnImageLoaded ); - } + mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); - mNextImage = image; } void ResizeImage() @@ -709,16 +692,7 @@ private: Stage stage = Stage::GetCurrent(); Size imageSize = stage.GetSize() * mImageStageScale; - // If an image is already loading, queue another load when it has finished. - // This way we get continuous updates instead of constantly re-requesting loads. - if( mImageLoading ) - { - mQueuedImageLoad = true; - } - else - { - LoadImage(); - } + LoadImage(); // Border size needs to be modified to take into account the width of the frame. Vector2 borderScale( ( imageSize + Vector2( BORDER_WIDTH * 2.0f, BORDER_WIDTH * 2.0f ) ) / stage.GetSize() ); @@ -741,7 +715,6 @@ private: Toolkit::ImageView mGrabCorner; PanGestureDetector mPanGestureDetector; Toolkit::ImageView mImageView; - ResourceImage mNextImage; //< Currently-loading image Vector2 mImageStageScale; int mCurrentPath; FittingMode::Type mFittingMode; @@ -759,7 +732,7 @@ void RunTest( Application& application ) } // Entry point for Linux & Tizen applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );