1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmLayout.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 1 $ 14 *---------------------------------------------------------------------------*/ 15 #ifndef SM_LAYOUT_H_ 16 #define SM_LAYOUT_H_ 17 18 #include <nw/lyt.h> 19 20 #include "../include/SmDef.h" 21 #include "../include/SmBase.h" 22 #include "../include/SmRectCollision.h" 23 24 25 //------------------------------------------------------------------------------ 26 //! ���C�A�E�g���\�[�X���Ǘ�����N���X�ł��B 27 class SmLayoutResource : public SmBase 28 { 29 public: 30 //! �A�j���[�V�����z�� 31 #define ANIM_COUNT (32) 32 typedef nw::ut::FixedSizeArray<nw::lyt::AnimTransform*, ANIM_COUNT> AnimationArray; 33 34 public: 35 //! �R���X�g���N�^�ł��B SmLayoutResource()36 SmLayoutResource() 37 : m_Layout( NULL ) 38 { 39 m_AnimationArray.clear(); 40 } 41 42 //! �f�X�g���N�^�ł��B ~SmLayoutResource()43 ~SmLayoutResource() 44 { 45 SM_SAFE_DELETE( m_Layout ); 46 } 47 48 //! ���C�A�E�g���\�[�X�����������܂��B InitLayout(const void * bclyt,nw::lyt::ArcResourceAccessor * pResAccessor)49 bool InitLayout( const void* bclyt, nw::lyt::ArcResourceAccessor* pResAccessor ) 50 { 51 NW_NULL_ASSERT(!m_Layout); 52 NW_NULL_ASSERT(bclyt); 53 NW_NULL_ASSERT(pResAccessor); 54 55 m_Layout = new nw::lyt::Layout(); 56 NW_NULL_ASSERT( m_Layout ); 57 58 if ( !m_Layout->Build( bclyt, pResAccessor ) ) 59 { 60 NW_FATAL_ERROR("can not build layout resource.\n"); 61 } 62 63 return true; 64 } 65 66 //! �A�j���[�V�������\�[�X��lj����܂��B AddAnimation(const void * bclan,nw::lyt::ArcResourceAccessor * pResAccessor)67 bool AddAnimation( const void* bclan, nw::lyt::ArcResourceAccessor* pResAccessor ) 68 { 69 NW_NULL_ASSERT(m_Layout); 70 NW_NULL_ASSERT(bclan); 71 NW_NULL_ASSERT(pResAccessor); 72 73 nw::lyt::AnimTransform* pAnimTrans = m_Layout->CreateAnimTransform( bclan, pResAccessor ); 74 if ( !pAnimTrans ) return false; 75 m_Layout->BindAnimation( pAnimTrans ); 76 m_Layout->UnbindAnimation( NULL ); 77 m_AnimationArray.push_back( pAnimTrans ); 78 79 return true; 80 } 81 82 //! �ێ����Ă���A�j���[�V���������擾���܂��B GetAnimationNum()83 uint GetAnimationNum() const 84 { 85 return m_AnimationArray.size(); 86 } 87 88 //! �w��A�j���[�V�����̃t���[���T�C�Y���擾���܂��B GetAnimationFrameSize(uint animNo)89 f32 GetAnimationFrameSize( uint animNo ) const 90 { 91 if ( animNo > GetAnimationNum() ) return 0.f; 92 93 return m_AnimationArray[animNo]->GetFrameSize(); 94 } 95 96 //! �w��Pane�̋�`���擾���܂��B GetOriginalRect(const char * name)97 nw::ut::Rect GetOriginalRect( const char* name ) const 98 { 99 nw::lyt::Pane* rootPane = m_Layout->GetRootPane(); 100 NW_NULL_ASSERT( rootPane ); 101 nw::lyt::Pane* pane = rootPane->FindPaneByName( name ); 102 NW_NULL_ASSERT( pane ); 103 return pane->GetPaneRect(); 104 } 105 106 //! �w��Pane�̋�`(�X�N���[�����W)���擾���܂��B 107 nw::ut::Rect GetRect( const char* name ); 108 109 //! �w��Pane���擾���܂��B GetPane(const char * name)110 nw::lyt::Pane* GetPane( const char* name ) const 111 { 112 nw::lyt::Pane* rootPane = m_Layout->GetRootPane(); 113 NW_NULL_ASSERT( rootPane ); 114 nw::lyt::Pane* pane = rootPane->FindPaneByName( name ); 115 return pane; 116 } 117 118 //! ���C�A�E�g���擾���܂��B GetLayout()119 nw::lyt::Layout* GetLayout() { return m_Layout; } 120 121 //! �A�j���[�V�����z����擾���܂��B GetAnimationArray()122 AnimationArray& GetAnimationArray() { return m_AnimationArray; } 123 124 private: 125 nw::lyt::Layout* m_Layout; 126 AnimationArray m_AnimationArray; 127 }; 128 129 130 //------------------------------------------------------------------------------ 131 //! ���C�A�E�g��\������N���X�ł��B 132 class SmLayout : public SmBase 133 { 134 public: 135 //! �R���X�g���N�^�ł��B 136 SmLayout( SmLayoutResource* layoutResource ); 137 138 //! �f�X�g���N�^�ł��B 139 ~SmLayout(); 140 141 //! �\���ʒu(���C�A�E�g���W�n)��ݒ肵�܂��B 142 void SetPosition( f32 x, f32 y ); 143 144 //! �\���ʒu(���C�A�E�g���W�n)���擾���܂��B GetPosX()145 f32 GetPosX() const { return m_Position.x; } GetPosY()146 f32 GetPosY() const { return m_Position.y; } 147 148 //! �w��y�C���̕\���ʒu(���C�A�E�g���W�n)��ݒ肵�܂��B 149 //! �X���C�_�Ŏg�p���Ă��܂��B����A�P�̃y�C�������ێ��ł��܂���B SetPanePosition(nw::lyt::Pane * pane,f32 x,f32 y)150 void SetPanePosition( nw::lyt::Pane* pane, f32 x, f32 y ) 151 { 152 m_OffsetPane = pane; 153 m_OffsetPosition.x = x; 154 m_OffsetPosition.y = y; 155 m_OffsetPosition.z = 0.f; 156 } 157 158 //! �Đ�����A�j���[�V������ݒ肵�܂��B 159 bool SetAnimationNo( uint animTransformNo ); 160 161 //! �A�j���[�V�����t���[����ݒ肵�܂��B 162 void SetAnimationFrame( f32 setFrame ); 163 164 //! �A�j���[�V�����t���[�����w��t���[�������i�߂܂��B 165 bool AddAnimationFrame( f32 addFrame, bool loop = true ); 166 167 //! ���݂̃A�j���[�V�����t���[�����擾���܂��B GetAnimationFrame()168 f32 GetAnimationFrame() const 169 { 170 return m_AnimationFrame; 171 } 172 173 //! �\��/��\����ݒ肵�܂��B SetVisible(bool visible)174 void SetVisible( bool visible ) 175 { 176 m_Visible = visible; 177 } 178 179 //! �\��/��\���̏�Ԃ��擾���܂��B GetVisible()180 bool GetVisible() const 181 { 182 return m_Visible; 183 } 184 185 //! �w��y�C���̕\��/��\����ݒ肵�܂��B SetVisiblePane(const char * paneName,bool visible)186 void SetVisiblePane( const char* paneName, bool visible ) 187 { 188 nw::lyt::Pane* pane = m_LayoutResource->GetPane( paneName ); 189 if( pane ) 190 { 191 pane->SetVisible( visible ); 192 } 193 } 194 195 //! ���C�A�E�g���\�[�X���擾���܂��B GetLayoutResource()196 SmLayoutResource* GetLayoutResource() const 197 { 198 return m_LayoutResource; 199 } 200 201 //! ���C�A�E�g���\�[�X�Ɍ��݂̃f�[�^�f���܂��B 202 bool SetupLayout(); 203 204 //! ���C�A�E�g���\�[�X�ɔ��f�����f�[�^��߂��܂��B 205 void ResetLayout(); 206 207 //! �e�L�X�g�{�b�N�X�ɕ\�����镶�����ݒ肵�܂��B SetString(const wchar_t * string)208 void SetString( const wchar_t* string ) 209 { 210 // todo 211 m_String = string; 212 } 213 214 private: 215 SmLayoutResource* m_LayoutResource; 216 nw::lyt::Pane* m_OffsetPane; 217 218 nw::math::VEC3 m_Position; 219 nw::math::VEC3 m_OffsetPosition; 220 221 f32 m_AnimationFrame; 222 u32 m_AnimationNo; 223 bool m_Visible; 224 const wchar_t* m_String; 225 }; 226 227 228 #endif // SM_LAYOUT_H_ 229