1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: SmLayout.cpp
4
5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain proprietary
8 information of Nintendo and/or its licensed developers and are protected by
9 national and international copyright laws. They may not be disclosed to third
10 parties or copied or duplicated in any form, in whole or in part, without the
11 prior written consent of Nintendo.
12
13 The content herein is highly confidential and should be handled accordingly.
14
15 $Revision: $
16 *---------------------------------------------------------------------------*/
17 #include <nn/os.h>
18
19 #include <nw/types.h>
20 #include <nw/ut.h>
21
22 #include "../include/SmLayout.h"
23
24 namespace
25 {
26
27 /*!--------------------------------------------------------------------------*
28 @brief 指定Paneの矩形(スクリーン座標)を取得します。
29 *---------------------------------------------------------------------------*/
GetRect(const char * name)30 nw::ut::Rect SmLayoutResource::GetRect( const char* name )
31 {
32 nw::ut::Rect rect;
33 const nw::lyt::Pane* pane = GetPane( name );
34 if ( !pane ) return rect;
35
36 rect = pane->GetPaneRect();
37 nw::math::VEC3 pos = pane->GetTranslate();
38
39 // スクリーン座標系に修正します。
40 rect.top = -rect.top;
41 rect.bottom = -rect.bottom;
42
43 // 矩形の中心を考慮します。
44 f32 posx = 0.f;
45 f32 posy = 0.f;
46
47 switch( pane->GetBasePositionH() )
48 {
49 case nw::lyt::HORIZONTALPOSITION_LEFT:
50 posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x;
51 break;
52
53 case nw::lyt::HORIZONTALPOSITION_CENTER:
54 posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x - rect.GetWidth()/2.f;
55 break;
56
57 case nw::lyt::HORIZONTALPOSITION_RIGHT:
58 posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x;
59 break;
60 }
61
62 switch( pane->GetBasePositionV() )
63 {
64 case nw::lyt::VERTICALPOSITION_TOP:
65 posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y;
66 break;
67
68 case nw::lyt::VERTICALPOSITION_CENTER:
69 posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y - rect.GetHeight()/2.f;
70 break;
71
72 case nw::lyt::VERTICALPOSITION_BOTTOM:
73 posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y;
74 break;
75 }
76
77 rect.MoveTo( posx, posy );
78
79 return rect;
80 }
81
82
83
84
85 /*!--------------------------------------------------------------------------*
86 @brief コンストラクタ。
87 *---------------------------------------------------------------------------*/
SmLayout(SmLayoutResource * layoutResource)88 SmLayout::SmLayout( SmLayoutResource* layoutResource )
89 : m_LayoutResource( layoutResource ),
90 m_OffsetPane( NULL ),
91 m_AnimationFrame( 0.0f ),
92 m_AnimationNo( 0 ),
93 m_Visible( true ),
94 m_String( NULL )
95 {
96 SetPosition( 0.f, 0.f );
97 }
98
99
100 /*!--------------------------------------------------------------------------*
101 @brief デストラクタ。
102 *---------------------------------------------------------------------------*/
~SmLayout()103 SmLayout::~SmLayout()
104 {
105
106 }
107
108
109 /*!--------------------------------------------------------------------------*
110 @brief 指定ペインの表示位置(レイアウト座標系)を設定します。
111 *---------------------------------------------------------------------------*/
112 void
SetPosition(f32 x,f32 y)113 SmLayout::SetPosition( f32 x, f32 y )
114 {
115 m_Position.x = x;
116 m_Position.y = - y;
117 m_Position.z = 0.0f;
118 }
119
120
121 /*!--------------------------------------------------------------------------*
122 @brief 再生するアニメーションを設定します。
123 *---------------------------------------------------------------------------*/
124 bool
SetAnimationNo(uint animTransformNo)125 SmLayout::SetAnimationNo( uint animTransformNo )
126 {
127 if ( animTransformNo > m_LayoutResource->GetAnimationNum() ) return false;
128 m_AnimationNo = animTransformNo;
129 return true;
130 }
131
132
133 /*!--------------------------------------------------------------------------*
134 @brief アニメーションフレームを設定します。
135 *---------------------------------------------------------------------------*/
136 void
SetAnimationFrame(f32 setFrame)137 SmLayout::SetAnimationFrame( f32 setFrame )
138 {
139 m_AnimationFrame = setFrame;
140 }
141
142
143 /*!--------------------------------------------------------------------------*
144 @brief アニメーションフレームを指定フレームだけ進めます。
145 *---------------------------------------------------------------------------*/
146 bool
AddAnimationFrame(f32 addFrame,bool loop)147 SmLayout::AddAnimationFrame( f32 addFrame, bool loop )
148 {
149 bool ret = false;
150 if ( m_AnimationNo >= m_LayoutResource->GetAnimationNum() ) return ret;
151 f32 frameSize = m_LayoutResource->GetAnimationFrameSize( m_AnimationNo );
152
153 // フレームに加算します。
154 m_AnimationFrame += addFrame;
155
156 // 最終フレーム
157 if ( m_AnimationFrame > frameSize )
158 {
159 if ( loop )
160 {
161 m_AnimationFrame = 0.f;
162 }
163 else
164 {
165 m_AnimationFrame -= frameSize;
166 }
167
168 ret = true;
169 }
170 return ret;
171 }
172
173
174 /*!--------------------------------------------------------------------------*
175 @brief レイアウトリソースに現在のデータを反映します。
176 *---------------------------------------------------------------------------*/
177 bool
SetupLayout()178 SmLayout::SetupLayout()
179 {
180 nw::lyt::Layout* layout = m_LayoutResource->GetLayout();
181 if ( !layout ) return false;
182
183 // レイアウト全体の表示位置を設定します。
184 nw::lyt::Pane* pane = layout->GetRootPane();
185 if ( pane )
186 {
187 pane->SetTranslate( m_Position );
188 }
189
190 // さらにオフセットをかけるPaneが指定されていれば、位置を設定します。
191 if ( m_OffsetPane )
192 {
193 m_OffsetPane->SetTranslate( m_OffsetPosition );
194 }
195
196 // アニメーションを設定します。
197 if ( m_AnimationNo < m_LayoutResource->GetAnimationNum() )
198 {
199 SmLayoutResource::AnimationArray& animArray = m_LayoutResource->GetAnimationArray();
200
201 // アニメーションを設定する
202 if ( !animArray.empty() )
203 {
204 layout->UnbindAnimation( NULL );
205 layout->BindAnimation( animArray[m_AnimationNo] );
206
207 animArray[m_AnimationNo]->SetFrame( m_AnimationFrame );
208 }
209 }
210
211 return true;
212 }
213
214
215 /*!--------------------------------------------------------------------------*
216 @brief レイアウトリソースに反映したデータを戻します。
217 *---------------------------------------------------------------------------*/
218 void
ResetLayout()219 SmLayout::ResetLayout()
220 {
221 // オフセットをかけたPaneを戻します。
222 if ( m_OffsetPane )
223 {
224 m_OffsetPane->SetTranslate( nw::math::VEC3::Zero() );
225 }
226 }
227
228
229
230 } // namespace
231
232
233