/*
- * Copyright (c) 2016 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.
*/
#include <dali/dali.h>
+#include <dali/devel-api/actors/actor-devel.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/popup/popup.h>
#include "shared/view.h"
Toolkit::ImageView background = Toolkit::ImageView::New();
background.SetProperty( Toolkit::ImageView::Property::IMAGE, backgroundImage );
- background.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
background.SetSize( stage.GetSize() );
stage.Add( background );
widthPixel[2] = 0x4f;
mHeightBox = Toolkit::ImageView::New( heightBackground );
- mHeightBox.SetOpacity( 0.2f );
+ mHeightBox.SetProperty( DevelActor::Property::OPACITY, 0.2f );
background.Add( mHeightBox );
mWidthBox = Toolkit::ImageView::New( widthBackground );
- mWidthBox.SetOpacity( 0.2f );
+ mWidthBox.SetProperty( DevelActor::Property::OPACITY, 0.2f );
background.Add( mWidthBox );
mDesiredBox = Toolkit::ImageView::New( BORDER_IMAGE );
background.Add( mDesiredBox );
mDesiredBox.SetSize( stage.GetSize() * mImageStageScale );
- mDesiredBox.SetParentOrigin( ParentOrigin::CENTER );
- mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER );
+ mDesiredBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mDesiredBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height );
- mHeightBox.SetParentOrigin( ParentOrigin::CENTER );
- mHeightBox.SetAnchorPoint( AnchorPoint::CENTER );
+ mHeightBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mHeightBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height );
- mWidthBox.SetParentOrigin( ParentOrigin::CENTER );
- mWidthBox.SetAnchorPoint( AnchorPoint::CENTER );
+ mWidthBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mWidthBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
// Initialize the actor
mImageView = Toolkit::ImageView::New( IMAGE_PATHS[ 0 ] );
// Reposition the actor
- mImageView.SetParentOrigin( ParentOrigin::CENTER );
- mImageView.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
mDesiredBox.Add( mImageView );
mGrabCorner = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE );
mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- mGrabCorner.SetName( "GrabCorner" );
- mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
- mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
+ 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.SetPosition( -BORDER_WIDTH, -BORDER_WIDTH );
- mGrabCorner.SetOpacity( 0.6f );
+ mGrabCorner.SetProperty( DevelActor::Property::OPACITY, 0.6f );
Layer grabCornerLayer = Layer::New();
- grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
- grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
+ grabCornerLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT );
+ grabCornerLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT );
grabCornerLayer.Add( mGrabCorner );
mDesiredBox.Add( grabCornerLayer );
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:
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( DevelActor::Property::OPACITY, 0.6f );
controlsLayer.Add( imagePrevious );
- imagePrevious.SetName( PREVIOUS_BUTTON_ID );
+ imagePrevious.SetProperty( Dali::Actor::Property::NAME, PREVIOUS_BUTTON_ID );
imagePrevious.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched );
// Next image button:
Toolkit::ImageView imageNext = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) );
- imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
+ imageNext.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
imageNext.SetY( playWidth * 0.5f );
imageNext.SetX( stage.GetSize().x - playWidth * 0.5f );
- imageNext.SetOpacity( 0.6f );
+ imageNext.SetProperty( DevelActor::Property::OPACITY, 0.6f );
controlsLayer.Add( imageNext );
- imageNext.SetName( NEXT_BUTTON_ID );
+ imageNext.SetProperty( Dali::Actor::Property::NAME, NEXT_BUTTON_ID );
imageNext.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched );
// Buttons to popup selectors for fitting and sampling modes:
modesGroupBackground.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE ) );
modesGroupBackground.SetFitHeight( 0 );
- modesGroupBackground.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
- modesGroupBackground.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
+ modesGroupBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
+ modesGroupBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
modesGroupBackground.SetPosition( 0.0f, 0.0f );
controlsLayer.Add( modesGroupBackground );
{
Toolkit::PushButton button = Toolkit::PushButton::New();
button.SetStyleName( STYLE_BUTTON_TEXT );
- button.SetName( id );
- button.SetLabelText( label );
+ 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.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked );
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.SetProperty( Dali::Actor::Property::NAME, "POPUP" );
+ popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
popup.SetSize( POPUP_WIDTH_DP, 0.0f );
popup.OutsideTouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnPopupOutsideTouched );
Toolkit::PushButton CreatePopupButton( Actor parent, const char* id )
{
Toolkit::PushButton button = Toolkit::PushButton::New();
- button.SetName( id );
- button.SetLabelText( id );
+ button.SetProperty( Dali::Actor::Property::NAME, id );
+ button.SetProperty( Toolkit::Button::Property::LABEL, id );
- button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- button.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
+ 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 );
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();
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();
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.SetLabelText( modeName );
+ mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName );
ResizeImage();
mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
mPopup.Reset();
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.SetLabelText( modeName );
+ mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName );
ResizeImage();
mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
mPopup.Reset();
}
}
- 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 TouchData& event )
{
if(event.GetPointCount() > 0)
{
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;
{
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.SetDisplayState( Toolkit::Popup::HIDDEN );
mPopup.Reset();
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
{
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()
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() );
Toolkit::ImageView mGrabCorner;
PanGestureDetector mPanGestureDetector;
Toolkit::ImageView mImageView;
- ResourceImage mNextImage; //< Currently-loading image
Vector2 mImageStageScale;
int mCurrentPath;
FittingMode::Type mFittingMode;
};
-void RunTest( Application& application )
-{
- ImageScalingAndFilteringController 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, DEMO_THEME_PATH );
-
- RunTest( application );
-
+ ImageScalingAndFilteringController test( application );
+ application.MainLoop();
return 0;
}