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