/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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 "shared/view.h"
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
using namespace Dali;
const char* IMAGE_PATH[] = {
DEMO_IMAGE_DIR "gallery-small-23.jpg",
DEMO_IMAGE_DIR "woodEffect.jpg",
+ DEMO_IMAGE_DIR "wood.png", // 32bits image
DEMO_IMAGE_DIR "heartsframe.9.png",
DEMO_IMAGE_DIR "World.svg"
};
enum CellPlacement
{
TOP_BUTTON,
+ MID_BUTTON,
LOWER_BUTTON,
IMAGE,
NUMBER_OF_ROWS
unsigned int GetButtonIndex( Toolkit::Button button )
{
- std::string buttonName = button.GetName();
+ std::string buttonName = button.GetProperty< std::string >( Dali::Actor::Property::NAME );
unsigned int index = 0;
if ( buttonName != "")
const unsigned int NUMBER_OF_RESOURCES = sizeof(IMAGE_PATH) / sizeof(char*);
std::string EXAMPLE_INSTRUCTIONS = "Instructions: Change button cycles through different image visuals, "
- "on/off takes the ImageView and it's current visual on or off stage.";
+ "on/off takes the ImageView and it's current visual on or off window.";
+
+const float CORNER_RADIUS_VALUE( 20.0f );
} // namespace
// The Init signal is received once (only) during the Application lifetime
// Creates a default view with a default tool bar.
- // The view is added to the stage.
+ // The view is added to the window.
mContentLayer = DemoHelper::CreateView( application,
mView,
mToolBar,
// Create a table view to show a pair of buttons above each image.
mTable = Toolkit::TableView::New( CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES );
- mTable.SetAnchorPoint( AnchorPoint::CENTER );
- mTable.SetParentOrigin( ParentOrigin::CENTER );
+ mTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+ mTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
mTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
Vector3 offset( 0.9f, 0.70f, 0.0f );
- mTable.SetSizeModeFactor( offset );
+ mTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset );
mTable.SetFitHeight(CellPlacement::TOP_BUTTON);
+ mTable.SetFitHeight(CellPlacement::MID_BUTTON);
mTable.SetFitHeight(CellPlacement::LOWER_BUTTON);
mContentLayer.Add( mTable );
Toolkit::TextLabel instructions = Toolkit::TextLabel::New( EXAMPLE_INSTRUCTIONS );
instructions.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
- instructions.SetParentOrigin(ParentOrigin::BOTTOM_CENTER);
- instructions.SetY(-50.0f);
+ instructions.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_CENTER);
+ instructions.SetProperty( Actor::Property::POSITION_Y, -50.0f);
instructions.SetProperty( Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL, true );
instructions.SetProperty( Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 10 );
mContentLayer.Add(instructions);
{
Toolkit::PushButton button = Toolkit::PushButton::New();
button.SetProperty( Toolkit::Button::Property::LABEL, "on/off" );
- button.SetParentOrigin( ParentOrigin::TOP_CENTER );
- button.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnStage );
+ button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+ button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+ button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnWindow );
button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
std::string s = std::to_string(x);
- button.SetName( s );
+ button.SetProperty( Dali::Actor::Property::NAME, s );
mTable.AddChild( button, Toolkit::TableView::CellPosition( CellPlacement::TOP_BUTTON, x ) );
Toolkit::PushButton button2 = Toolkit::PushButton::New();
button2.SetProperty( Toolkit::Button::Property::LABEL, "Change" );
- button2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
- button2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+ button2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+ button2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
button2.ClickedSignal().Connect( this, &ImageViewController::ChangeImageClicked );
button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
button2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
- button2.SetName( s );
- mTable.AddChild( button2, Toolkit::TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) );
-
- mImageViews[x] = Toolkit::ImageView::New( IMAGE_PATH[ 0 ] );
- mImageViews[x].SetParentOrigin( ParentOrigin::CENTER );
- mImageViews[x].SetAnchorPoint( AnchorPoint::CENTER );
+ button2.SetProperty( Dali::Actor::Property::NAME, s );
+ mTable.AddChild( button2, Toolkit::TableView::CellPosition( CellPlacement::MID_BUTTON, x ) );
+
+ Toolkit::PushButton button3 = Toolkit::PushButton::New();
+ button3.SetProperty( Toolkit::Button::Property::LABEL, "Round" );
+ button3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+ button3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
+ button3.ClickedSignal().Connect( this, &ImageViewController::RoundedCornerClicked );
+ button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+ button3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+ button3.SetProperty( Dali::Actor::Property::NAME, s );
+ mTable.AddChild( button3, Toolkit::TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) );
+
+ mImageViews[x] = Toolkit::ImageView::New( );
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+ imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ 0 ] );
+ mImageViews[x].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+
+
+ mImageViews[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mImageViews[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
mImageViews[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
mTable.AddChild( mImageViews[x], Toolkit::TableView::CellPosition( CellPlacement::IMAGE, x ) );
// Set changeable counter and toggle for each ImageView
- mImageViewImageIndexStatus[x] = true;
+ mImageViewImageIndexStatus[x] = 0;
mImageViewToggleStatus[x] = true;
+ mImageViewRoundedCornerStatus[x] = false;
}
- Stage::GetCurrent().KeyEventSignal().Connect(this, &ImageViewController::OnKeyEvent);
+ application.GetWindow().KeyEventSignal().Connect(this, &ImageViewController::OnKeyEvent);
}
private:
- bool ToggleImageOnStage( Toolkit::Button button )
+ void ImmediateLoadImage( const char* urlToLoad )
+ {
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+ imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, urlToLoad );
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( imagePropertyMap );
+ visual.Reset();
+ }
+
+ bool ToggleImageOnWindow( Toolkit::Button button )
{
unsigned int buttonIndex = GetButtonIndex( button );
}
else
{
- mTable.AddChild( imageView, Toolkit::TableView::CellPosition( 2, GetButtonIndex( button ) ) );
+ mTable.AddChild( imageView, Toolkit::TableView::CellPosition( CellPlacement::IMAGE, GetButtonIndex( button ) ) );
}
mImageViewToggleStatus[ buttonIndex ] = !mImageViewToggleStatus[ buttonIndex ];
{
unsigned int buttonIndex = GetButtonIndex( button );
- if ( mImageViews[buttonIndex].OnStage() )
+ if( mImageViews[buttonIndex].GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
{
- mImageViews[buttonIndex].SetImage( IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
-
++mImageViewImageIndexStatus[buttonIndex];
if( mImageViewImageIndexStatus[buttonIndex] == NUMBER_OF_RESOURCES )
{
mImageViewImageIndexStatus[buttonIndex] = 0;
}
+
+ // Reset corner radius state value
+ mImageViewRoundedCornerStatus[buttonIndex] = false;
+
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+ imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
+ mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+ }
+ return true;
+ }
+
+ bool RoundedCornerClicked( Toolkit::Button button )
+ {
+ unsigned int buttonIndex = GetButtonIndex( button );
+
+ if( mImageViews[buttonIndex].GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
+ {
+ mImageViewRoundedCornerStatus[ buttonIndex ] = !mImageViewRoundedCornerStatus[ buttonIndex ];
+
+ Property::Map imagePropertyMap;
+ imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+ imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
+ imagePropertyMap.Insert( Toolkit::DevelVisual::Property::CORNER_RADIUS, mImageViewRoundedCornerStatus[buttonIndex] ? CORNER_RADIUS_VALUE : 0.0f );
+
+ mImageViews[buttonIndex].SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap );
}
return true;
}
Toolkit::TableView mTable;
Toolkit::ImageView mImageViews[ NUMBER_OF_IMAGES ];
bool mImageViewToggleStatus[ NUMBER_OF_IMAGES ];
+ bool mImageViewRoundedCornerStatus[ NUMBER_OF_IMAGES ];
unsigned int mImageViewImageIndexStatus[ NUMBER_OF_IMAGES ];
Toolkit::TableView::CellPosition mCurrentPositionToggle;