view.h
6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef __DALI_DEMO_HELPER_VIEW_H__
#define __DALI_DEMO_HELPER_VIEW_H__
/*
* Copyright (c) 2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <dali-toolkit/dali-toolkit.h>
namespace DemoHelper
{
/**
* Provide a style for the view and its tool bar.
*/
struct ViewStyle
{
ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float dpi, float toolBarHeight, float toolBarPadding )
: mToolBarButtonPercentage( toolBarButtonPercentage ),
mToolBarTitlePercentage( toolBarTitlePercentage ),
mDpi( dpi ),
mToolBarHeight( toolBarHeight ),
mToolBarPadding( toolBarPadding )
{}
float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width.
float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width.
float mDpi; ///< This style is indented for the given dpi.
float mToolBarHeight; ///< The tool bar height for the given dpi above.
float mToolBarPadding; ///< The tool bar padding between controls for the given dpi above.
};
const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 315.f, 80.f, 4.f );
const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
const Dali::PointSize DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
const Dali::TextStyle::Weight DEFAULT_TEXT_STYLE_WEIGHT(Dali::TextStyle::EXTRALIGHT);
const Dali::Vector4 DEFAULT_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f);
const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
static Dali::TextStyle defaultTextStyle;
static bool textStyleSet=false;
Dali::TextStyle& GetDefaultTextStyle()
{
if(!textStyleSet)
{
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);
textStyleSet = true;
}
return defaultTextStyle;
}
Dali::Layer CreateView( Dali::Application& application,
Dali::Toolkit::View& view,
Dali::Toolkit::ToolBar& toolBar,
const std::string& backgroundImagePath,
const std::string& toolbarImagePath,
const std::string& title,
const ViewStyle& style,
const Dali::TextStyle& textStyle )
{
Dali::Stage stage = Dali::Stage::GetCurrent();
// Create default View.
view = Dali::Toolkit::View::New();
// Add the view to the stage before setting the background.
stage.Add( view );
// Set background image.
if ( ! backgroundImagePath.empty() )
{
Dali::Image backgroundImage = Dali::Image::New( backgroundImagePath );
Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage );
view.SetBackground( backgroundImageActor );
}
// FIXME
// Connects the orientation signal with the View::OrientationChanged method.
//application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
// Create default ToolBar
Dali::Vector2 dpi = stage.GetDpi();
// Create toolbar layer.
Dali::Layer toolBarLayer = Dali::Layer::New();
toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
toolBarLayer.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::SourceWidthFixedHeight( style.mToolBarHeight * dpi.y / style.mDpi ) ) );
toolBarLayer.SetSize( 0.0f, style.mToolBarHeight * dpi.y / style.mDpi );
// Add tool bar layer to the view.
view.AddContentLayer( toolBarLayer );
// Raise tool bar layer to the top.
toolBarLayer.RaiseToTop();
// Tool bar
Dali::Image image = Dali::Image::New( toolbarImagePath );
Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image );
toolBar = Dali::Toolkit::ToolBar::New();
toolBar.SetBackground( toolBarBackground );
toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
toolBar.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
toolBar.SetSize( 0.0f, style.mToolBarHeight * dpi.y / style.mDpi );
toolBarBackground.SetSortModifier(1.0f);
// Add the tool bar to the too bar layer.
toolBarLayer.Add( toolBar );
Dali::Font font = Dali::Font::New();
// Tool bar text.
if( !title.empty() )
{
Dali::Toolkit::TextView titleActor = Dali::Toolkit::TextView::New();
titleActor.SetName( "ToolbarTitle" );
titleActor.SetText( title );
titleActor.SetSize( font.MeasureText( title ) );
titleActor.SetStyleToCurrentText(textStyle);
// Add title to the tool bar.
const float padding( style.mToolBarPadding * dpi.x / style.mDpi );
toolBar.AddControl( titleActor, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
}
// Create a content layer.
Dali::Layer contentLayer = Dali::Layer::New();
contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
contentLayer.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
view.AddContentLayer( contentLayer );
contentLayer.LowerBelow( toolBarLayer );
return contentLayer;
}
Dali::Layer CreateView( Dali::Application& application,
Dali::Toolkit::View& view,
Dali::Toolkit::ToolBar& toolBar,
const std::string& backgroundImagePath,
const std::string& toolbarImagePath,
const std::string& title,
const ViewStyle& style = DEFAULT_VIEW_STYLE )
{
return CreateView( application, view, toolBar, backgroundImagePath, toolbarImagePath, title, style,
GetDefaultTextStyle() );
}
} // DemoHelper
#endif // __DALI_DEMO_HELPER_VIEW_H__