X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fimage-scaling-and-filtering%2Fimage-scaling-and-filtering-example.cpp;h=7c7a0f09a32ff737e90b7c3821b5c4ffc890d78d;hb=2e182925204bf3ef9f2a36cbfbf998e79fbafaf5;hp=882687a457288f75c24f713b6e412c614daf6c1f;hpb=14d695efd0c2ceef45ef1111119437edeafe3084;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 882687a..7c7a0f0 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) 2017 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. @@ -16,7 +16,9 @@ */ #include +#include #include +#include #include "shared/view.h" #include @@ -26,54 +28,53 @@ using Toolkit::TextLabel; namespace { -const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); +const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); +const char* BORDER_IMAGE( DEMO_IMAGE_DIR "border-4px.9.png" ); +const int BORDER_WIDTH = ( 11.0f + 4.0f ); // Shadow size = 11, border size = 4. +const char* RESIZE_HANDLE_IMAGE( DEMO_IMAGE_DIR "resize-handle.png" ); + const int MARGIN_SIZE = 10; const char* const NEXT_BUTTON_ID = "NEXT_BUTTON"; const char* const PREVIOUS_BUTTON_ID = "PREVIOUS_BUTTON"; -const char * const DALI_ICON_PLAY = DALI_IMAGE_DIR "icon-play.png"; - -const char* const PUSHBUTTON_PRESS_IMAGE = DALI_IMAGE_DIR "button-down.9.png"; -const char* const PUSHBUTTON_BUTTON_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; -const char* const PUSHBUTTON_DISABLED_IMAGE = DALI_IMAGE_DIR "button-disabled.9.png"; +const char * const DALI_ICON_PLAY = DEMO_IMAGE_DIR "icon-play.png"; const char* const FITTING_BUTTON_ID = "FITTING_BUTTON"; 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[] = { + // Variety of sizes, shapes and formats: + DEMO_IMAGE_DIR "dali-logo.png", + DEMO_IMAGE_DIR "layer1.png", + DEMO_IMAGE_DIR "layer2.png", + DEMO_IMAGE_DIR "animation-list.png", + DEMO_IMAGE_DIR "music-libray-main-screen.png", + DEMO_IMAGE_DIR "music-libray-record-cover.png", + DEMO_IMAGE_DIR "contacts-background.png", + DEMO_IMAGE_DIR "portrait_screen_primitive_shapes.gif", + DEMO_IMAGE_DIR "landscape_screen_primitive_shapes.gif", + DEMO_IMAGE_DIR "square_primitive_shapes.bmp", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "book-landscape-cover.jpg", + DEMO_IMAGE_DIR "book-portrait-p1.jpg", + DEMO_IMAGE_DIR "book-landscape-cover-back.jpg", + // Worst case for aliasing in downscaling, 2k x 2k 1 bit per pixel dithered // black and white image: - DALI_IMAGE_DIR "gallery-large-14.wbmp", - // Variety of sizes, shapes and formats: - DALI_IMAGE_DIR "animation-list.png", - DALI_IMAGE_DIR "layer1.png", - DALI_IMAGE_DIR "layer2.png", - DALI_IMAGE_DIR "music-libray-main-screen.png", - DALI_IMAGE_DIR "music-libray-record-cover.png", - DALI_IMAGE_DIR "contacts-background.png", - DALI_IMAGE_DIR "portrait_screen_primitive_shapes.gif", - DALI_IMAGE_DIR "landscape_screen_primitive_shapes.gif", - DALI_IMAGE_DIR "square_primitive_shapes.bmp", - DALI_IMAGE_DIR "dali-logo.png", - DALI_IMAGE_DIR "com.samsung.dali-demo.ico", - DALI_IMAGE_DIR "gallery-large-14.jpg", - DALI_IMAGE_DIR "book-landscape-cover.jpg", - DALI_IMAGE_DIR "book-portrait-p1.jpg", - DALI_IMAGE_DIR "book-landscape-cover-back.jpg", - DALI_IMAGE_DIR "background-1.jpg", - DALI_IMAGE_DIR "background-blocks.jpg", - DALI_IMAGE_DIR "background-magnifier.jpg", - DALI_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "gallery-large-14.wbmp", + + DEMO_IMAGE_DIR "background-1.jpg", + DEMO_IMAGE_DIR "background-blocks.jpg", + DEMO_IMAGE_DIR "background-magnifier.jpg", + DEMO_IMAGE_DIR "gallery-large-14.jpg", NULL }; const int NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; @@ -152,10 +153,13 @@ public: ImageScalingAndFilteringController( Application& application ) : mApplication( application ), + mLastPinchScale( 1.0f ), mImageStageScale( 0.5f, 0.5f ), mCurrentPath( 0 ), - mFittingMode( FittingMode::SCALE_TO_FILL ), - mSamplingMode( SamplingMode::BOX_THEN_LINEAR) + mFittingMode( FittingMode::FIT_WIDTH ), + mSamplingMode( SamplingMode::BOX_THEN_LINEAR), + mImageLoading( false ), + mQueuedImageLoad( false ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &ImageScalingAndFilteringController::Create ); @@ -169,23 +173,27 @@ public: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Apply the default theme: - DemoHelper::RequestThemeChange(); - // Get a handle to the stage Stage stage = Stage::GetCurrent(); + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + // Background image: - ResourceImage backgroundImage = ResourceImage::New( BACKGROUND_IMAGE, ImageDimensions( stage.GetSize().width, stage.GetSize().height ), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR ); - ImageActor background = ImageActor::New( backgroundImage ); - background.SetZ( -2.0f ); - background.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - background.SetSize( stage.GetSize() ); + Dali::Property::Map backgroundImage; + 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 ); + background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + background.SetProperty( Actor::Property::SIZE, stage.GetSize() ); stage.Add( background ); - // Make grey pixels for the desired box, the desired height the desired width: - BufferImage desiredBackground = BufferImage::WHITE(); - BufferImage heightBackground = BufferImage::WHITE(); PixelBuffer* const heightPixel = heightBackground.GetBuffer(); heightPixel[0] = 0x8f; @@ -198,67 +206,64 @@ public: widthPixel[1] = 0x4f; widthPixel[2] = 0x4f; - mHeightBox = ImageActor::New( heightBackground ); - mHeightBox.SetOpacity( 0.2f ); - stage.Add( mHeightBox ); - - mWidthBox = ImageActor::New( widthBackground ); - mWidthBox.SetOpacity( 0.2f ); - stage.Add( mWidthBox ); - - mDesiredBox = ImageActor::New( desiredBackground ); - stage.Add( mDesiredBox ); - - mDesiredBox.SetSize( stage.GetSize() * mImageStageScale ); - mDesiredBox.SetParentOrigin( ParentOrigin::CENTER ); - mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER ); - mDesiredBox.SetPosition( 0, 0, -1 ); - - mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); - mHeightBox.SetParentOrigin( ParentOrigin::CENTER ); - mHeightBox.SetAnchorPoint( AnchorPoint::CENTER ); - mHeightBox.SetPosition( 0, 0, -1 ); - - mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); - mWidthBox.SetParentOrigin( ParentOrigin::CENTER ); - mWidthBox.SetAnchorPoint( AnchorPoint::CENTER ); - mWidthBox.SetPosition( 0, 0, -1 ); - - // Make a grab-handle for resizing the image: - mGrabCorner = Toolkit::PushButton::New(); - mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mGrabCorner.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); - mGrabCorner.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); - mGrabCorner.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); - mGrabCorner.SetName( "GrabCorner" ); - mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); - mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); - mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) ); - mGrabCorner.SetZ( 1.0f ); - mGrabCorner.SetOpacity( 0.6f ); - mDesiredBox.Add( mGrabCorner ); - mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( mGrabCorner ); - mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); + mHeightBox = Toolkit::ImageView::New( heightBackground ); + mHeightBox.SetProperty( DevelActor::Property::OPACITY, 0.2f ); + background.Add( mHeightBox ); + + mWidthBox = Toolkit::ImageView::New( widthBackground ); + mWidthBox.SetProperty( DevelActor::Property::OPACITY, 0.2f ); + background.Add( mWidthBox ); + + mDesiredBox = Toolkit::ImageView::New( BORDER_IMAGE ); + background.Add( mDesiredBox ); + + mDesiredBox.SetProperty( Actor::Property::SIZE, stage.GetSize() * mImageStageScale ); + mDesiredBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mDesiredBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + + mHeightBox.SetProperty( Actor::Property::SIZE, Vector2( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ) ); + mHeightBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mHeightBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + + mWidthBox.SetProperty( Actor::Property::SIZE, Vector2( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ) ); + mWidthBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mWidthBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); // Initialize the actor - mImageActor = ImageActor::New(); + mImageView = Toolkit::ImageView::New( IMAGE_PATHS[ 0 ] ); // Reposition the actor - mImageActor.SetParentOrigin( ParentOrigin::CENTER ); - mImageActor.SetAnchorPoint( AnchorPoint::CENTER ); + mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); // Display the actor on the stage - stage.Add( mImageActor ); + mDesiredBox.Add( mImageView ); - mImageActor.SetSize( stage.GetSize() * mImageStageScale ); + mImageView.SetProperty( Actor::Property::SIZE, stage.GetSize() * mImageStageScale ); // Setup the pinch detector for scaling the desired image load dimensions: mPinchDetector = PinchGestureDetector::New(); - mPinchDetector.Attach( mImageActor ); + mPinchDetector.Attach( mImageView ); mPinchDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPinch ); + mGrabCorner = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE ); + mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mGrabCorner.SetProperty( Dali::Actor::Property::NAME, "GrabCorner" ); + mGrabCorner.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); + mGrabCorner.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); + mGrabCorner.SetProperty( Actor::Property::POSITION, Vector2( -BORDER_WIDTH, -BORDER_WIDTH )); + mGrabCorner.SetProperty( DevelActor::Property::OPACITY, 0.6f ); + + Layer grabCornerLayer = Layer::New(); + grabCornerLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); + grabCornerLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); + grabCornerLayer.Add( mGrabCorner ); + mDesiredBox.Add( grabCornerLayer ); + + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.Attach( mGrabCorner ); + mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); + // Tie-in input event handlers: stage.KeyEventSignal().Connect( this, &ImageScalingAndFilteringController::OnKeyEvent ); @@ -276,35 +281,34 @@ public: Dali::Layer controlsLayer = Dali::Layer::New(); controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - controlsLayer.SetSizeModeFactor( Vector3( 1.0f, 1.0f, 1.0f ) ); - controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); - controlsLayer.SetParentOrigin( ParentOrigin::TOP_LEFT); + controlsLayer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, 1.0f, 1.0f ) ); + controlsLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + controlsLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); stage.Add( controlsLayer ); // 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 ); - Actor imagePrevious = ImageActor::New( playImage ); + Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); // Last image button: - imagePrevious.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + imagePrevious.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); imagePrevious.RotateBy( Radian(3.14159265358979323846f), Vector3( 0, 1.0f, 0 ) ); - imagePrevious.SetY( playWidth * 0.5f ); - imagePrevious.SetX( playWidth + playWidth * 0.5f ); - imagePrevious.SetOpacity( 0.6f ); + imagePrevious.SetProperty( Actor::Property::POSITION_Y, playWidth * 0.5f ); + imagePrevious.SetProperty( Actor::Property::POSITION_X, playWidth + playWidth * 0.5f ); + imagePrevious.SetProperty( DevelActor::Property::OPACITY, 0.6f ); controlsLayer.Add( imagePrevious ); - imagePrevious.SetName( PREVIOUS_BUTTON_ID ); - imagePrevious.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + imagePrevious.SetProperty( Dali::Actor::Property::NAME, PREVIOUS_BUTTON_ID ); + imagePrevious.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); // Next image button: - Actor imageNext = ImageActor::New( playImage ); - imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); - imageNext.SetY( playWidth * 0.5f ); - imageNext.SetX( stage.GetSize().x - playWidth * 0.5f ); - imageNext.SetOpacity( 0.6f ); + Toolkit::ImageView imageNext = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); + imageNext.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); + imageNext.SetProperty( Actor::Property::POSITION_Y, playWidth * 0.5f ); + imageNext.SetProperty( Actor::Property::POSITION_X, stage.GetSize().x - playWidth * 0.5f ); + imageNext.SetProperty( DevelActor::Property::OPACITY, 0.6f ); controlsLayer.Add( imageNext ); - imageNext.SetName( NEXT_BUTTON_ID ); - imageNext.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + imageNext.SetProperty( Dali::Actor::Property::NAME, NEXT_BUTTON_ID ); + imageNext.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); // Buttons to popup selectors for fitting and sampling modes: @@ -316,9 +320,9 @@ public: modesGroupBackground.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE ) ); modesGroupBackground.SetFitHeight( 0 ); - modesGroupBackground.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); - modesGroupBackground.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); - modesGroupBackground.SetPosition( 0.0f, 0.0f ); + modesGroupBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); + modesGroupBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); + modesGroupBackground.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f )); controlsLayer.Add( modesGroupBackground ); @@ -333,11 +337,10 @@ 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 ) ); - button.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); fittingModeGroup.Add( button ); mFittingModeButton = button; @@ -355,11 +358,10 @@ 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 ) ); - button.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); samplingModeGroup.Add( button ); mSamplingModeButton = button; @@ -370,14 +372,11 @@ 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.SetName( id ); - button.SetLabel( label ); + button.SetStyleName( STYLE_BUTTON_TEXT ); + button.SetProperty( Dali::Actor::Property::NAME, id ); + button.SetProperty( Toolkit::Button::Property::LABEL, label ); button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - button.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); - button.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); - button.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); return button; } @@ -388,30 +387,24 @@ public: const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f; Toolkit::Popup popup = Toolkit::Popup::New(); - popup.SetName( "POPUP" ); - popup.SetParentOrigin( ParentOrigin::CENTER ); - popup.SetAnchorPoint( AnchorPoint::CENTER ); - popup.SetSize( POPUP_WIDTH_DP, 0.0f ); - popup.HideTail(); + popup.SetProperty( Dali::Actor::Property::NAME, "POPUP" ); + popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) ); popup.OutsideTouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnPopupOutsideTouched ); return popup; } - //void CreatePopupButton( Toolkit::Popup popup, const char* id ) Toolkit::PushButton CreatePopupButton( Actor parent, const char* id ) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetName( id ); - button.SetLabel( id ); - button.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); - button.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); - Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( button.GetLabel() ); - textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f ); - - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); + button.SetProperty( Dali::Actor::Property::NAME, id ); + button.SetProperty( Toolkit::Button::Property::LABEL, id ); + + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); @@ -423,7 +416,7 @@ public: bool OnButtonClicked( Toolkit::Button button ) { - if( button.GetName() == FITTING_BUTTON_ID ) + if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == FITTING_BUTTON_ID ) { mPopup = CreatePopup(); @@ -431,7 +424,6 @@ public: Toolkit::TableView fittingModes = Toolkit::TableView::New( 4, 1 ); fittingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); fittingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - fittingModes.SetBackgroundColor( BACKGROUND_COLOUR ); fittingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); fittingModes.SetFitHeight( 0 ); fittingModes.SetFitHeight( 1 ); @@ -443,10 +435,11 @@ public: CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_WIDTH ) ); CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_HEIGHT ) ); - mPopup.Add( fittingModes ); - mPopup.Show(); + mPopup.SetContent( fittingModes ); + Stage::GetCurrent().Add( mPopup ); + mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); } - else if( button.GetName() == SAMPLING_BUTTON_ID ) + else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == SAMPLING_BUTTON_ID ) { mPopup = CreatePopup(); @@ -454,7 +447,6 @@ public: Toolkit::TableView samplingModes = Toolkit::TableView::New( 6, 1 ); samplingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); samplingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - samplingModes.SetBackgroundColor( BACKGROUND_COLOUR ); samplingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); samplingModes.SetFitHeight( 0 ); samplingModes.SetFitHeight( 1 ); @@ -470,8 +462,9 @@ public: CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_LINEAR ) ); CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NO_FILTER ) ); - mPopup.Add( samplingModes ); - mPopup.Show(); + mPopup.SetContent( samplingModes ); + Stage::GetCurrent().Add( mPopup ); + mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); } else if( CheckFittingModeButton( button, FittingMode::SCALE_TO_FILL) || CheckFittingModeButton( button, FittingMode::SHRINK_TO_FIT) || @@ -494,13 +487,12 @@ public: bool CheckFittingModeButton( Actor &button, FittingMode::Type mode ) { const char * const modeName = StringFromScalingMode( mode ); - if( button.GetName() == modeName ) + if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == modeName ) { mFittingMode = mode; - mFittingModeButton.SetLabel( modeName ); - mFittingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); ResizeImage(); - mPopup.Hide(); + mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); return true; } @@ -510,13 +502,12 @@ public: bool CheckSamplingModeButton( Actor &button, SamplingMode::Type mode ) { const char * const modeName = StringFromFilterMode( mode ); - if( button.GetName() == modeName ) + if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == modeName ) { mSamplingMode = mode; - mSamplingModeButton.SetLabel( modeName ); - mSamplingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); ResizeImage(); - mPopup.Hide(); + mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); return true; } @@ -527,28 +518,20 @@ public: { if( mPopup ) { - mPopup.Hide(); + mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); } } - void OnImageLoaded( ResourceImage image ) - { - DALI_ASSERT_DEBUG( image == mNextImage ); - mImageActor.SetImage( image ); - mImageActor.SetSize( Size( image.GetWidth(), image.GetHeight() ) ); - } - - 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(); + const std::string & name = actor.GetProperty< std::string >( Dali::Actor::Property::NAME ); if( name == NEXT_BUTTON_ID ) { mCurrentPath = mCurrentPath + 1; @@ -581,7 +564,7 @@ public: } const float scale = pinch.scale; - if( scale != mLastPinchScale ) + if( ! Equals( scale, mLastPinchScale ) ) { if ( scale < mLastPinchScale ) { @@ -601,8 +584,10 @@ public: void OnPan( Actor actor, const PanGesture& gesture ) { Stage stage = Stage::GetCurrent(); - mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x + (gesture.displacement.x * 2.0f / stage.GetSize().width ) ) ); - mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y + (gesture.displacement.y * 2.0f / stage.GetSize().height ) ) ); + // 1.0f and 0.75f are the maximum size caps of the resized image, as a factor of stage-size. + mImageStageScale.x = std::max( 0.05f, std::min( 0.95f, mImageStageScale.x + ( gesture.displacement.x * 2.0f / stage.GetSize().width ) ) ); + mImageStageScale.y = std::max( 0.05f, std::min( 0.70f, mImageStageScale.y + ( gesture.displacement.y * 2.0f / stage.GetSize().height ) ) ); + ResizeImage(); } @@ -612,9 +597,9 @@ public: { if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) { - if( mPopup && mPopup.IsVisible() ) + if( mPopup && mPopup.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) { - mPopup.Hide(); + mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); mPopup.Reset(); } else @@ -662,15 +647,13 @@ public: else if ( event.keyPressedName == "f" ) { mSamplingMode = NextFilterMode( mSamplingMode ); - mSamplingModeButton.SetLabel( StringFromFilterMode( mSamplingMode ) ); - mSamplingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromFilterMode( mSamplingMode ) ); } // Cycle filter and scaling modes: else if ( event.keyPressedName == "s" ) { mFittingMode = NextScalingMode( mFittingMode ); - mFittingModeButton.SetLabel( StringFromScalingMode( mFittingMode ) ); - mFittingModeButton.GetLabel().SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT ); + mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromScalingMode( mFittingMode ) ); } else { @@ -682,57 +665,69 @@ public: } private: + + void LoadImage() + { + mImageLoading = true; + + const char * const path = IMAGE_PATHS[ mCurrentPath ]; + Stage stage = Stage::GetCurrent(); + Size imageSize = stage.GetSize() * mImageStageScale; + mImageView.SetProperty( Actor::Property::SIZE, imageSize ); + + 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; + + mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + + } + void ResizeImage() { - const char * const path = IMAGE_PATHS[mCurrentPath]; Stage stage = Stage::GetCurrent(); Size imageSize = stage.GetSize() * mImageStageScale; - const ImageDimensions imageSizeInt = ImageDimensions::FromFloatArray( &imageSize.x ); - ResourceImage image = ResourceImage::New( path, imageSizeInt, mFittingMode, mSamplingMode ); - image.LoadingFinishedSignal().Connect( this, &ImageScalingAndFilteringController::OnImageLoaded ); + LoadImage(); - mNextImage = image; + // 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() ); + mDesiredBox.SetProperty( Actor::Property::SIZE, stage.GetSize() * borderScale ); - mDesiredBox.SetSize( stage.GetSize() * mImageStageScale ); - mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ); - mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ); + mHeightBox.SetProperty( Actor::Property::SIZE, Vector2( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height ) ); + mWidthBox.SetProperty( Actor::Property::SIZE, Vector2( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height ) ); } private: Application& mApplication; - Actor mDesiredBox; //< Background rectangle to show requested image size. - Actor mHeightBox; //< Background horizontal stripe to show requested image height. - Actor mWidthBox; //< Background vertical stripe to show requested image width. + Toolkit::ImageView mDesiredBox; //< Background rectangle to show requested image size. + Toolkit::ImageView mHeightBox; //< Background horizontal stripe to show requested image height. + Toolkit::ImageView mWidthBox; //< Background vertical stripe to show requested image width. Toolkit::PushButton mFittingModeButton; Toolkit::PushButton mSamplingModeButton; Toolkit::Popup mPopup; PinchGestureDetector mPinchDetector; float mLastPinchScale; - Toolkit::PushButton mGrabCorner; + Toolkit::ImageView mGrabCorner; PanGestureDetector mPanGestureDetector; - ImageActor mImageActor; - ResourceImage mNextImage; //< Currently-loading image + Toolkit::ImageView mImageView; Vector2 mImageStageScale; int mCurrentPath; FittingMode::Type mFittingMode; SamplingMode::Type mSamplingMode; + bool mImageLoading; + bool mQueuedImageLoad; + }; -void RunTest( Application& application ) +int DALI_EXPORT_API main( int argc, char **argv ) { + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); ImageScalingAndFilteringController 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; }