2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 #include "navigation-bar.h"
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 ),
44 mInternalNavigationControl.ItemPushedSignal().Connect( this, &NavigationBar::OnItemPushed );
45 mInternalNavigationControl.ItemPoppedSignal().Connect( this, &NavigationBar::OnItemPopped );
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);
53 SetBackground( mBasicCurrentStyle->background );
56 NavigationBar::~NavigationBar()
60 void NavigationBar::ScaleStyleUpdate( Vector2 naviControlSize, int orientation )
62 bool isPortrait( orientation == 0 || orientation == 180 );
63 // change in orientation.
64 if(mIsPortrait != isPortrait)
66 mIsPortrait = isPortrait;
67 mBasicCurrentStyle = isPortrait ? &mBasicStylePortrait : &mBasicStyleLandscape;
68 OrientationUpdate( isPortrait );
69 mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
70 mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
73 mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
77 mRelativeScale = naviControlSize.x / static_cast<float>( mBasicCurrentStyle->referenceWidth);
78 mLayout.SetScale(mRelativeScale);
79 mBarHeight = mBasicCurrentStyle->height * mRelativeScale;
82 mBackground.SetScale(mRelativeScale);
86 float NavigationBar::GetBarHeight() const
98 void NavigationBar::SetBackground( Actor background )
100 mBackground = background;
101 mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
102 mInternalNavigationControl.GetBarLayer().Add( mBackground );
103 mBackground.SetScale(mRelativeScale);
106 void NavigationBar::OnItemPushed( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
108 mCurrentItem = naviItem;
109 Update( mCurrentItem );
112 void NavigationBar::OnItemPopped( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
114 mCurrentItem = mInternalNavigationControl.GetCurrentItem();
115 Update( mCurrentItem );
118 } // namespace Internal
120 } // namespace Toolkit