1 #ifndef __DALI_DEMO_HELPER_VIEW_H__
2 #define __DALI_DEMO_HELPER_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali-toolkit/dali-toolkit.h>
27 * Provide a style for the view and its tool bar.
31 ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding )
32 : mToolBarButtonPercentage( toolBarButtonPercentage ),
33 mToolBarTitlePercentage( toolBarTitlePercentage ),
34 mToolBarHeight( toolBarHeight ),
35 mToolBarPadding( toolBarPadding )
38 float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width.
39 float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width.
40 float mToolBarHeight; ///< The tool bar height (in pixels).
41 float mToolBarPadding; ///< The tool bar padding (in pixels)..
44 const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f );
46 const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
47 const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
48 const float DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
49 const Dali::Vector4 DEFAULT_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f);
51 const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
52 const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
54 float ScalePointSize(int pointSize)
56 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
57 float meanDpi = (dpi.height + dpi.width) * 0.5f;
58 return pointSize * 220.0f / meanDpi; // 220 is the default horizontal DPI defined in adaptor Application
61 Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
62 const std::string& toolbarImagePath,
63 const std::string& title,
64 const ViewStyle& style )
66 Dali::Stage stage = Dali::Stage::GetCurrent();
68 Dali::Layer toolBarLayer = Dali::Layer::New();
69 toolBarLayer.SetName( "TOOLBAR_LAYER" );
70 toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
71 toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
72 toolBarLayer.SetPreferredSize( Dali::Vector2( 0.0f, style.mToolBarHeight ) );
73 toolBarLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::WIDTH );
74 toolBarLayer.SetResizePolicy( Dali::FIXED, Dali::HEIGHT );
76 // Raise tool bar layer to the top.
77 toolBarLayer.RaiseToTop();
80 Dali::Image image = Dali::ResourceImage::New( toolbarImagePath );
81 Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image );
82 toolBarBackground.SetName( "TOOLBAR_BACKGROUND" );
83 toolBarBackground.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
84 toolBar = Dali::Toolkit::ToolBar::New();
85 toolBar.SetName( "TOOLBAR" );
86 toolBar.SetBackground( toolBarBackground );
87 toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
88 toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
89 toolBar.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
90 toolBarBackground.SetSortModifier(1.0f);
92 // Add the tool bar to the too bar layer.
93 toolBarLayer.Add( toolBar );
98 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New();
99 label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT );
100 label.SetDrawMode( Dali::DrawMode::OVERLAY );
101 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
102 label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title );
103 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
104 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
105 label.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::HEIGHT );
106 label.SetColor( DEFAULT_TEXT_STYLE_COLOR );
107 toolBarLayer.Add( label );
113 Dali::Layer CreateView( Dali::Application& application,
114 Dali::Toolkit::View& view,
115 Dali::Toolkit::ToolBar& toolBar,
116 const std::string& backgroundImagePath,
117 const std::string& toolbarImagePath,
118 const std::string& title,
119 const ViewStyle& style = DEFAULT_VIEW_STYLE )
121 Dali::Stage stage = Dali::Stage::GetCurrent();
123 // Create default View.
124 view = Dali::Toolkit::View::New();
125 view.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
127 // Add the view to the stage before setting the background.
130 // Set background image, loading it at screen resolution:
131 if ( !backgroundImagePath.empty() )
133 Dali::ImageAttributes backgroundAttributes;
134 backgroundAttributes.SetSize( stage.GetSize() );
135 backgroundAttributes.SetFilterMode( Dali::ImageAttributes::BoxThenLinear );
136 backgroundAttributes.SetScalingMode( Dali::ImageAttributes::ScaleToFill );
137 Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, backgroundAttributes );
138 Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage );
139 view.SetBackground( backgroundImageActor );
143 // Connects the orientation signal with the View::OrientationChanged method.
144 //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
146 // Create default ToolBar
147 Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
149 // Add tool bar layer to the view.
150 view.AddContentLayer( toolBarLayer );
152 // Create a content layer.
153 Dali::Layer contentLayer = Dali::Layer::New();
154 contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
155 contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
156 contentLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
157 view.AddContentLayer( contentLayer );
158 contentLayer.LowerBelow( toolBarLayer );
163 Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text )
165 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text );
166 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
167 label.SetDrawMode( Dali::DrawMode::OVERLAY );
168 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
169 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
170 label.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::HEIGHT );
171 label.SetColor( DEFAULT_TEXT_STYLE_COLOR );
178 #endif // __DALI_DEMO_HELPER_VIEW_H__