const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
+const unsigned int IMAGE_WIDTH = 256;
+const unsigned int IMAGE_HEIGHT = 256;
+const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8;
+
AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear,
AlphaFunctions::EaseIn,
AlphaFunctions::EaseOut };
const float MENU_OPTION_HEIGHT(140.0f);
const float LABEL_TEXT_SIZE_Y = 20.0f;
-const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
-const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
-const PointSize DEFAULT_TEXT_STYLE_POINT_SIZE( 5.0f );
-const TextStyle::Weight DEFAULT_TEXT_STYLE_WEIGHT(Dali::TextStyle::MEDIUM);
-const Vector4 DEFAULT_TEXT_STYLE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
-
const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
static Vector3 DepthLayoutItemSizeFunctionPortrait(unsigned int numberOfColumns, float layoutWidth)
*/
void OnInit(Application& app)
{
+ DemoHelper::RequestThemeChange();
+
Stage stage = Dali::Stage::GetCurrent();
stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
TOOLBAR_IMAGE,
"" );
- mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
+ app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
// Create an edit mode button. (left of toolbar)
Toolkit::PushButton editButton = Toolkit::PushButton::New();
mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
mDeleteButton.SetDrawMode( DrawMode::OVERLAY );
- mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) );
- mDeleteButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
+ mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
+ mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
mDeleteButton.SetLeaveRequired( true );
mDeleteButton.SetVisible( false );
mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
mInsertButton.SetDrawMode( DrawMode::OVERLAY );
- mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) );
+ mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
mInsertButton.SetLeaveRequired( true );
mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
mReplaceButton.SetDrawMode( DrawMode::OVERLAY );
- mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) );
+ mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
mReplaceButton.SetLeaveRequired( true );
stage.Add( mReplaceButton );
// Create the item view actor
+ mImageAtlas = CreateImageAtlas();
mItemView = ItemView::New(*this);
mItemView.SetParentOrigin(ParentOrigin::CENTER);
mItemView.SetAnchorPoint(AnchorPoint::CENTER);
* Orientation changed signal callback
* @param orientation
*/
- void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation )
+ void OnOrientationChanged( Orientation orientation )
{
const unsigned int angle = orientation.GetDegrees();
virtual Actor NewItem(unsigned int itemId)
{
// Create an image actor for this item
- Image image = ResourceImage::New( IMAGE_PATHS[itemId % NUM_IMAGES] );
- Actor actor = ImageActor::New(image);
+ unsigned int imageId = itemId % NUM_IMAGES;
+ ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH,
+ (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT,
+ IMAGE_WIDTH,
+ IMAGE_HEIGHT );
+ Actor actor = ImageActor::New(mImageAtlas, pixelArea);
actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
// Add a border image child actor
borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
- borderActor.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT );
+ borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE );
actor.Add(borderActor);
actor.SetKeyboardFocusable( true );
private:
/**
+ * Create an Atlas to tile the images inside.
+ */
+ Atlas CreateImageAtlas()
+ {
+ const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS;
+ const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast<float>(NUM_IMAGES)/ static_cast<float>(NUM_IMAGE_PER_ROW_IN_ATLAS));
+ Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888);
+
+ for( unsigned int i = 0; i < NUM_IMAGES; i++ )
+ {
+ atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT );
+ }
+
+ return atlas;
+ }
+
+ /**
* Sets/Updates the title of the View
* @param[in] title The new title for the view.
*/
{
if(!mTitleActor)
{
- mTitleActor = TextView::New();
+ mTitleActor = DemoHelper::CreateToolBarLabel( "" );
// Add title to the tool bar.
mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
}
- Font font = Font::New();
- mTitleActor.SetText( title );
- mTitleActor.SetSize( font.MeasureText( title ) );
- mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
+ mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
}
void ShowMenu()
mMenu = Toolkit::Popup::New();
mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+ mMenu.SetSize( popupWidth, MENU_OPTION_HEIGHT * 2 );
mMenu.OutsideTouchedSignal().Connect( this, &ItemViewExample::HideMenu );
- stage.Add( mMenu );
TableView tableView = TableView::New( 0, 0 );
- Vector2 tableSize = Vector2( popupWidth, MENU_OPTION_HEIGHT * 2 );
- tableView.SetSize( tableSize );
+ tableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
mMenu.Add( tableView );
Slider slider = Slider::New();
- slider.SetProperty( Slider::LOWER_BOUND_PROPERTY, 0.0f );
- slider.SetProperty( Slider::UPPER_BOUND_PROPERTY, 3.0f );
- slider.SetProperty( Slider::VALUE_PROPERTY, mDurationSeconds );
- slider.SetProperty( Slider::VALUE_PRECISION_PROPERTY, 2 );
- slider.SetProperty( Slider::SHOW_POPUP_PROPERTY, true );
+ slider.SetProperty( Slider::Property::LOWER_BOUND, 0.0f );
+ slider.SetProperty( Slider::Property::UPPER_BOUND, 3.0f );
+ slider.SetProperty( Slider::Property::VALUE, mDurationSeconds );
+ slider.SetProperty( Slider::Property::VALUE_PRECISION, 2 );
+ slider.SetProperty( Slider::Property::SHOW_POPUP, true );
+ slider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
slider.ValueChangedSignal().Connect( this, &ItemViewExample::SliderValueChange );
tableView.AddChild( slider, TableView::CellPosition( 0, 0 ) );
- tableView.SetRelativeHeight( 0, 0.5f );
- TextStyle defaultTextStyle;
- defaultTextStyle.SetFontName(DEFAULT_TEXT_STYLE_FONT_FAMILY);
- defaultTextStyle.SetFontStyle(DEFAULT_TEXT_STYLE_FONT_STYLE);
- defaultTextStyle.SetFontPointSize(DEFAULT_TEXT_STYLE_POINT_SIZE);
- defaultTextStyle.SetWeight(DEFAULT_TEXT_STYLE_WEIGHT);
- defaultTextStyle.SetTextColor(DEFAULT_TEXT_STYLE_COLOR);
-
- TextView text = TextView::New( "Duration" );
+ TextLabel text = TextLabel::New( "Duration" );
text.SetAnchorPoint( ParentOrigin::TOP_LEFT );
text.SetParentOrigin( ParentOrigin::TOP_LEFT );
- text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft );
- text.SetStyleToCurrentText( defaultTextStyle );
- text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y );
- text.ApplyConstraint( Dali::Constraint::New<float>( Dali::Actor::Property::SizeWidth, Dali::ParentSource( Dali::Actor::Property::SizeWidth ), Dali::EqualToConstraint() ) );
- text.SetZ( -0.9f );
+ text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+ text.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
+ text.SetSize( Vector2( 0.0f, LABEL_TEXT_SIZE_Y ) );
slider.Add( text );
Actor textContainer = Actor::New();
- mAlphaFunctionText = TextView::New( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] );
+ textContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ mAlphaFunctionText = TextLabel::New( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] );
mAlphaFunctionText.SetAnchorPoint( ParentOrigin::CENTER );
mAlphaFunctionText.SetParentOrigin( ParentOrigin::CENTER );
- mAlphaFunctionText.SetTextAlignment( Toolkit::Alignment::VerticalCenter );
textContainer.Add( mAlphaFunctionText );
tableView.AddChild( textContainer, TableView::CellPosition( 1, 0 ) );
- tableView.SetRelativeHeight( 0, 0.5f );
mTapDetector = TapGestureDetector::New();
mTapDetector.Attach(mAlphaFunctionText);
mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ChangeAlphaFunctionOnTap );
- text = TextView::New( "Alpha Function" );
+ text = TextLabel::New( "Alpha Function" );
text.SetAnchorPoint( ParentOrigin::TOP_LEFT );
text.SetParentOrigin( ParentOrigin::TOP_LEFT );
- text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft );
- text.SetStyleToCurrentText( defaultTextStyle );
+ text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y );
- text.ApplyConstraint( Dali::Constraint::New<float>( Dali::Actor::Property::SizeWidth, Dali::ParentSource( Dali::Actor::Property::SizeWidth ), Dali::EqualToConstraint() ) );
textContainer.Add( text );
mMenu.Show();
if( mAlphaFunctionText )
{
- mAlphaFunctionText.SetText( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] );
+ mAlphaFunctionText.SetProperty( TextLabel::Property::TEXT, std::string(ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex]) );
}
if( mItemView )
Mode mMode;
bool mMenuShown;
- Toolkit::View mView;
+ Toolkit::Control mView;
unsigned int mOrientation;
Toolkit::ToolBar mToolBar;
- TextView mTitleActor; ///< The Toolbar's Title.
+ TextLabel mTitleActor; ///< The Toolbar's Title.
ItemView mItemView;
Image mBorderImage;
+ Atlas mImageAtlas;
unsigned int mCurrentLayout;
float mDurationSeconds;
Toolkit::PushButton mReplaceButton;
unsigned int mAlphaFuncIndex;
- TextView mAlphaFunctionText;
+ TextLabel mAlphaFunctionText;
BufferImage mWhiteImage;
};