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 );
50 const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
51 const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
53 void RequestThemeChange()
55 // Provide the stylesheet
56 Dali::Toolkit::StyleManager styleManager = Dali::Toolkit::StyleManager::Get();
57 styleManager.RequestThemeChange( DALI_DEMO_THEME_PATH );
60 float ScalePointSize(int pointSize)
62 Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
63 float meanDpi = (dpi.height + dpi.width) * 0.5f;
64 return pointSize * 220.0f / meanDpi; // 220 is the default horizontal DPI defined in adaptor Application
67 Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
68 const std::string& toolbarImagePath,
69 const std::string& title,
70 const ViewStyle& style )
72 Dali::Stage stage = Dali::Stage::GetCurrent();
74 Dali::Layer toolBarLayer = Dali::Layer::New();
75 toolBarLayer.SetName( "TOOLBAR_LAYER" );
76 toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
77 toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
78 toolBarLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH );
79 toolBarLayer.SetSize( 0.0f, style.mToolBarHeight );
81 // Raise tool bar layer to the top.
82 toolBarLayer.RaiseToTop();
85 Dali::Image image = Dali::ResourceImage::New( toolbarImagePath );
86 Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image );
87 toolBarBackground.SetName( "TOOLBAR_BACKGROUND" );
88 toolBarBackground.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
89 toolBar = Dali::Toolkit::ToolBar::New();
90 toolBar.SetName( "TOOLBAR" );
91 toolBar.SetBackground( toolBarBackground );
92 toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
93 toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
94 toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
95 toolBarBackground.SetSortModifier(1.0f);
97 // Add the tool bar to the too bar layer.
98 toolBarLayer.Add( toolBar );
103 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New();
104 label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT );
105 label.SetDrawMode( Dali::DrawMode::OVERLAY );
106 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
107 label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title );
108 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
109 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
110 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
112 // Add title to the tool bar.
113 const float padding( style.mToolBarPadding );
114 toolBar.AddControl( label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
120 Dali::Layer CreateView( Dali::Application& application,
121 Dali::Toolkit::Control& view,
122 Dali::Toolkit::ToolBar& toolBar,
123 const std::string& backgroundImagePath,
124 const std::string& toolbarImagePath,
125 const std::string& title,
126 const ViewStyle& style = DEFAULT_VIEW_STYLE )
128 Dali::Stage stage = Dali::Stage::GetCurrent();
130 // Create default View.
131 view = Dali::Toolkit::Control::New();
132 view.SetAnchorPoint( Dali::AnchorPoint::CENTER );
133 view.SetParentOrigin( Dali::ParentOrigin::CENTER );
134 view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
136 // Add the view to the stage before setting the background.
139 // Set background image, loading it at screen resolution:
140 if ( !backgroundImagePath.empty() )
142 Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, Dali::ImageDimensions( stage.GetSize().x, stage.GetSize().y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
143 view.SetBackgroundImage( backgroundImage );
147 // Connects the orientation signal with the View::OrientationChanged method.
148 //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
150 // Create default ToolBar
151 Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
153 // Add tool bar layer to the view.
154 view.Add( toolBarLayer );
156 // Create a content layer.
157 Dali::Layer contentLayer = Dali::Layer::New();
158 contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
159 contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
160 contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
161 view.Add( contentLayer );
162 contentLayer.LowerBelow( toolBarLayer );
167 Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text )
169 Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text );
170 label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
171 label.SetDrawMode( Dali::DrawMode::OVERLAY );
172 label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
173 label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
174 label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
181 #endif // __DALI_DEMO_HELPER_VIEW_H__