2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "navigation-bar.h"
35 NavigationBar::NavigationBar(NavigationControl& naviControl,
36 Toolkit::BasicNaviBarStyle barStylePortrait,
37 Toolkit::BasicNaviBarStyle barStyleLandscape )
38 :mInternalNavigationControl( naviControl ),
39 mBasicStylePortrait( barStylePortrait ),
40 mBasicStyleLandscape( barStyleLandscape ),
41 mBasicCurrentStyle( &mBasicStylePortrait ),
45 mInternalNavigationControl.ItemPushedSignal().Connect( this, &NavigationBar::OnItemPushed );
46 mInternalNavigationControl.ItemPoppedSignal().Connect( this, &NavigationBar::OnItemPopped );
48 mLayout = Toolkit::TableView::New(1,3);
49 mInternalNavigationControl.GetBarLayer().Add(mLayout);
50 mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
51 mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
52 mLayout.SetDrawMode(DrawMode::OVERLAY);
54 SetBackground( mBasicCurrentStyle->background );
57 NavigationBar::~NavigationBar()
61 void NavigationBar::ScaleStyleUpdate( Vector2 naviControlSize, int orientation )
63 bool isPortrait( orientation == 0 || orientation == 180 );
64 // change in orientation.
65 if(mIsPortrait != isPortrait)
67 mIsPortrait = isPortrait;
68 mBasicCurrentStyle = isPortrait ? &mBasicStylePortrait : &mBasicStyleLandscape;
69 OrientationUpdate( isPortrait );
70 mLayout.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
71 mLayout.SetFixedHeight(0, mBasicCurrentStyle->height);
74 mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
78 mRelativeScale = naviControlSize.x / static_cast<float>( mBasicCurrentStyle->referenceWidth);
79 mLayout.SetScale(mRelativeScale);
80 mBarHeight = mBasicCurrentStyle->height * mRelativeScale;
83 mBackground.SetScale(mRelativeScale);
87 float NavigationBar::GetBarHeight() const
99 void NavigationBar::SetBackground( Actor background )
101 mBackground = background;
102 mBackground.SetSize(mBasicCurrentStyle->referenceWidth, mBasicCurrentStyle->height);
103 mInternalNavigationControl.GetBarLayer().Add( mBackground );
104 mBackground.SetScale(mRelativeScale);
107 void NavigationBar::OnItemPushed( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
109 mCurrentItem = naviItem;
110 Update( mCurrentItem );
113 void NavigationBar::OnItemPopped( Toolkit::NavigationControl naviControl, Toolkit::Page naviItem )
115 mCurrentItem = mInternalNavigationControl.GetCurrentItem();
116 Update( mCurrentItem );
119 } // namespace Internal
121 } // namespace Toolkit