dfedc417ca9a8dc330c2c588db07988c05ebba56
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-frame / navigation-bar.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include "navigation-bar.h"
19
20 // EXTERNAL INCLUDES
21
22 // INTERNAL INCLUDES
23
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 NavigationBar::NavigationBar(NavigationControl& naviControl,
35                              Toolkit::BasicNaviBarStyle barStylePortrait,
36                              Toolkit::BasicNaviBarStyle barStyleLandscape )
37 :mInternalNavigationControl( naviControl ),
38  mBasicStylePortrait( barStylePortrait ),
39  mBasicStyleLandscape( barStyleLandscape ),
40  mBasicCurrentStyle( &mBasicStylePortrait ),
41  mIsPortrait( true ),
42  mVisible( true )
43 {
44   mInternalNavigationControl.ItemPushedSignal().Connect( this, &NavigationBar::OnItemPushed );
45   mInternalNavigationControl.ItemPoppedSignal().Connect( this, &NavigationBar::OnItemPopped );
46
47   mLayout = Toolkit::TableView::New(1,3);
48   mInternalNavigationControl.GetBarLayer().Add(mLayout);
49   mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
50   mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
51   mLayout.SetDrawMode(DrawMode::OVERLAY);
52
53   SetBackground( mBasicCurrentStyle->background );
54 }
55
56 NavigationBar::~NavigationBar()
57 {
58 }
59
60 void NavigationBar::ScaleStyleUpdate( Vector2 naviControlSize, int orientation )
61 {
62   bool isPortrait( orientation == 0 || orientation == 180 );
63   // change in orientation.
64   if(mIsPortrait != isPortrait)
65   {
66     mIsPortrait = isPortrait;
67     mBasicCurrentStyle = isPortrait ? &mBasicStylePortrait : &mBasicStyleLandscape;
68     OrientationUpdate( isPortrait );
69     mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
70     mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
71     if(mBackground)
72     {
73       mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
74     }
75   }
76
77   mRelativeScale = naviControlSize.x / static_cast<float>( mBasicCurrentStyle->referenceWidth);
78   mLayout.SetScale(mRelativeScale);
79   mBarHeight = mBasicCurrentStyle->height * mRelativeScale;
80   if(mBackground)
81   {
82     mBackground.SetScale(mRelativeScale);
83   }
84 }
85
86 float NavigationBar::GetBarHeight() const
87 {
88   if( mVisible )
89   {
90     return mBarHeight;
91   }
92   else
93   {
94     return 0.0f;
95   }
96 }
97
98 void NavigationBar::SetBackground( Actor background )
99 {
100   mBackground = background;
101   mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
102   mInternalNavigationControl.GetBarLayer().Add( mBackground );
103   mBackground.SetScale(mRelativeScale);
104 }
105
106 void NavigationBar::OnItemPushed( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
107 {
108   mCurrentItem = naviItem;
109   Update( mCurrentItem );
110 }
111
112 void NavigationBar::OnItemPopped( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
113 {
114   mCurrentItem = mInternalNavigationControl.GetCurrentItem();
115   Update( mCurrentItem );
116 }
117
118 } // namespace Internal
119
120 } // namespace Toolkit
121
122 } // namespace Dali