/*---------------------------------------------------------------------------* Project: NintendoWare File: SmLayout.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #ifndef SM_LAYOUT_H_ #define SM_LAYOUT_H_ #include #include "../include/SmDef.h" #include "../include/SmBase.h" #include "../include/SmRectCollision.h" //------------------------------------------------------------------------------ //! レイアウトリソースを管理するクラスです。 class SmLayoutResource : public SmBase { public: //! アニメーション配列 #define ANIM_COUNT (32) typedef nw::ut::FixedSizeArray AnimationArray; public: //! コンストラクタです。 SmLayoutResource() : m_Layout( NULL ) { m_AnimationArray.clear(); } //! デストラクタです。 ~SmLayoutResource() { SM_SAFE_DELETE( m_Layout ); } //! レイアウトリソースを初期化します。 bool InitLayout( const void* bclyt, nw::lyt::ArcResourceAccessor* pResAccessor ) { NW_NULL_ASSERT(!m_Layout); NW_NULL_ASSERT(bclyt); NW_NULL_ASSERT(pResAccessor); m_Layout = new nw::lyt::Layout(); NW_NULL_ASSERT( m_Layout ); if ( !m_Layout->Build( bclyt, pResAccessor ) ) { NW_FATAL_ERROR("can not build layout resource.\n"); } return true; } //! アニメーションリソースを追加します。 bool AddAnimation( const void* bclan, nw::lyt::ArcResourceAccessor* pResAccessor ) { NW_NULL_ASSERT(m_Layout); NW_NULL_ASSERT(bclan); NW_NULL_ASSERT(pResAccessor); nw::lyt::AnimTransform* pAnimTrans = m_Layout->CreateAnimTransform( bclan, pResAccessor ); if ( !pAnimTrans ) return false; m_Layout->BindAnimation( pAnimTrans ); m_Layout->UnbindAnimation( NULL ); m_AnimationArray.push_back( pAnimTrans ); return true; } //! 保持しているアニメーション数を取得します。 uint GetAnimationNum() const { return m_AnimationArray.size(); } //! 指定アニメーションのフレームサイズを取得します。 f32 GetAnimationFrameSize( uint animNo ) const { if ( animNo > GetAnimationNum() ) return 0.f; return m_AnimationArray[animNo]->GetFrameSize(); } //! 指定Paneの矩形を取得します。 nw::ut::Rect GetOriginalRect( const char* name ) const { nw::lyt::Pane* rootPane = m_Layout->GetRootPane(); NW_NULL_ASSERT( rootPane ); nw::lyt::Pane* pane = rootPane->FindPaneByName( name ); NW_NULL_ASSERT( pane ); return pane->GetPaneRect(); } //! 指定Paneの矩形(スクリーン座標)を取得します。 nw::ut::Rect GetRect( const char* name ); //! 指定Paneを取得します。 nw::lyt::Pane* GetPane( const char* name ) const { nw::lyt::Pane* rootPane = m_Layout->GetRootPane(); NW_NULL_ASSERT( rootPane ); nw::lyt::Pane* pane = rootPane->FindPaneByName( name ); return pane; } //! レイアウトを取得します。 nw::lyt::Layout* GetLayout() { return m_Layout; } //! アニメーション配列を取得します。 AnimationArray& GetAnimationArray() { return m_AnimationArray; } private: nw::lyt::Layout* m_Layout; AnimationArray m_AnimationArray; }; //------------------------------------------------------------------------------ //! レイアウトを表示するクラスです。 class SmLayout : public SmBase { public: //! コンストラクタです。 SmLayout( SmLayoutResource* layoutResource ); //! デストラクタです。 ~SmLayout(); //! 表示位置(レイアウト座標系)を設定します。 void SetPosition( f32 x, f32 y ); //! 表示位置(レイアウト座標系)を取得します。 f32 GetPosX() const { return m_Position.x; } f32 GetPosY() const { return m_Position.y; } //! 指定ペインの表示位置(レイアウト座標系)を設定します。 //! スライダで使用しています。現状、1つのペインしか保持できません。 void SetPanePosition( nw::lyt::Pane* pane, f32 x, f32 y ) { m_OffsetPane = pane; m_OffsetPosition.x = x; m_OffsetPosition.y = y; m_OffsetPosition.z = 0.f; } //! 再生するアニメーションを設定します。 bool SetAnimationNo( uint animTransformNo ); //! アニメーションフレームを設定します。 void SetAnimationFrame( f32 setFrame ); //! アニメーションフレームを指定フレームだけ進めます。 bool AddAnimationFrame( f32 addFrame, bool loop = true ); //! 現在のアニメーションフレームを取得します。 f32 GetAnimationFrame() const { return m_AnimationFrame; } //! 表示/非表示を設定します。 void SetVisible( bool visible ) { m_Visible = visible; } //! 表示/非表示の状態を取得します。 bool GetVisible() const { return m_Visible; } //! 指定ペインの表示/非表示を設定します。 void SetVisiblePane( const char* paneName, bool visible ) { nw::lyt::Pane* pane = m_LayoutResource->GetPane( paneName ); if( pane ) { pane->SetVisible( visible ); } } //! レイアウトリソースを取得します。 SmLayoutResource* GetLayoutResource() const { return m_LayoutResource; } //! レイアウトリソースに現在のデータを反映します。 bool SetupLayout(); //! レイアウトリソースに反映したデータを戻します。 void ResetLayout(); //! テキストボックスに表示する文字列を設定します。 void SetString( const wchar_t* string ) { // todo m_String = string; } private: SmLayoutResource* m_LayoutResource; nw::lyt::Pane* m_OffsetPane; nw::math::VEC3 m_Position; nw::math::VEC3 m_OffsetPosition; f32 m_AnimationFrame; u32 m_AnimationNo; bool m_Visible; const wchar_t* m_String; }; #endif // SM_LAYOUT_H_