/*---------------------------------------------------------------------------* Project: NintendoWare File: SmLayout.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 1 $ *---------------------------------------------------------------------------*/ #include #include #include #include "../include/SmLayout.h" namespace { /*!--------------------------------------------------------------------------* @brief 指定Paneの矩形(スクリーン座標)を取得します。 *---------------------------------------------------------------------------*/ nw::ut::Rect SmLayoutResource::GetRect( const char* name ) { nw::ut::Rect rect; const nw::lyt::Pane* pane = GetPane( name ); if ( !pane ) return rect; rect = pane->GetPaneRect(); nw::math::VEC3 pos = pane->GetTranslate(); // スクリーン座標系に修正します。 rect.top = -rect.top; rect.bottom = -rect.bottom; // 矩形の中心を考慮します。 f32 posx = 0.f; f32 posy = 0.f; switch( pane->GetBasePositionH() ) { case nw::lyt::HORIZONTALPOSITION_LEFT: posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x; break; case nw::lyt::HORIZONTALPOSITION_CENTER: posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x - rect.GetWidth()/2.f; break; case nw::lyt::HORIZONTALPOSITION_RIGHT: posx = SM_LOWER_SCREEN_HALF_SIZE_W + pos.x; break; } switch( pane->GetBasePositionV() ) { case nw::lyt::VERTICALPOSITION_TOP: posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y; break; case nw::lyt::VERTICALPOSITION_CENTER: posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y - rect.GetHeight()/2.f; break; case nw::lyt::VERTICALPOSITION_BOTTOM: posy = SM_LOWER_SCREEN_HALF_SIZE_H - pos.y; break; } rect.MoveTo( posx, posy ); return rect; } /*!--------------------------------------------------------------------------* @brief コンストラクタ。 *---------------------------------------------------------------------------*/ SmLayout::SmLayout( SmLayoutResource* layoutResource ) : m_LayoutResource( layoutResource ), m_OffsetPane( NULL ), m_AnimationFrame( 0.0f ), m_AnimationNo( 0 ), m_Visible( true ), m_String( NULL ) { SetPosition( 0.f, 0.f ); } /*!--------------------------------------------------------------------------* @brief デストラクタ。 *---------------------------------------------------------------------------*/ SmLayout::~SmLayout() { } /*!--------------------------------------------------------------------------* @brief 指定ペインの表示位置(レイアウト座標系)を設定します。 *---------------------------------------------------------------------------*/ void SmLayout::SetPosition( f32 x, f32 y ) { m_Position.x = x; m_Position.y = - y; m_Position.z = 0.0f; } /*!--------------------------------------------------------------------------* @brief 再生するアニメーションを設定します。 *---------------------------------------------------------------------------*/ bool SmLayout::SetAnimationNo( uint animTransformNo ) { if ( animTransformNo > m_LayoutResource->GetAnimationNum() ) return false; m_AnimationNo = animTransformNo; return true; } /*!--------------------------------------------------------------------------* @brief アニメーションフレームを設定します。 *---------------------------------------------------------------------------*/ void SmLayout::SetAnimationFrame( f32 setFrame ) { m_AnimationFrame = setFrame; } /*!--------------------------------------------------------------------------* @brief アニメーションフレームを指定フレームだけ進めます。 *---------------------------------------------------------------------------*/ bool SmLayout::AddAnimationFrame( f32 addFrame, bool loop ) { bool ret = false; if ( m_AnimationNo >= m_LayoutResource->GetAnimationNum() ) return ret; f32 frameSize = m_LayoutResource->GetAnimationFrameSize( m_AnimationNo ); // フレームに加算します。 m_AnimationFrame += addFrame; // 最終フレーム if ( m_AnimationFrame > frameSize ) { if ( loop ) { m_AnimationFrame = 0.f; } else { m_AnimationFrame -= frameSize; } ret = true; } return ret; } /*!--------------------------------------------------------------------------* @brief レイアウトリソースに現在のデータを反映します。 *---------------------------------------------------------------------------*/ bool SmLayout::SetupLayout() { nw::lyt::Layout* layout = m_LayoutResource->GetLayout(); if ( !layout ) return false; // レイアウト全体の表示位置を設定します。 nw::lyt::Pane* pane = layout->GetRootPane(); if ( pane ) { pane->SetTranslate( m_Position ); } // さらにオフセットをかけるPaneが指定されていれば、位置を設定します。 if ( m_OffsetPane ) { m_OffsetPane->SetTranslate( m_OffsetPosition ); } // アニメーションを設定します。 if ( m_AnimationNo < m_LayoutResource->GetAnimationNum() ) { SmLayoutResource::AnimationArray& animArray = m_LayoutResource->GetAnimationArray(); // アニメーションを設定する if ( !animArray.empty() ) { layout->UnbindAnimation( NULL ); layout->BindAnimation( animArray[m_AnimationNo] ); animArray[m_AnimationNo]->SetFrame( m_AnimationFrame ); } } return true; } /*!--------------------------------------------------------------------------* @brief レイアウトリソースに反映したデータを戻します。 *---------------------------------------------------------------------------*/ void SmLayout::ResetLayout() { // オフセットをかけたPaneを戻します。 if ( m_OffsetPane ) { m_OffsetPane->SetTranslate( nw::math::VEC3::Zero() ); } } } // namespace