1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmMessage.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 $Revision: 1 $ 13 *---------------------------------------------------------------------------*/ 14 #ifndef SM_MESSAGE_H_ 15 #define SM_MESSAGE_H_ 16 17 18 #include "../include/SmBase.h" 19 #include "../include/SmPrimitive.h" 20 21 22 // ���b�Z�[�W�̃^�C�v 23 enum 24 { 25 SM_MESSAGE_NONE = 0, //! �Ȃ� 26 SM_MESSAGE_TUCHPANEL_PRESS = 1, //! �^�b�`�p�l���������ꂽ 27 SM_MESSAGE_TUCHPANEL_RELEASE = 2, //! �^�b�`�p�l�����痣�ꂽ 28 SM_MESSAGE_TUCHPANEL_MOTION = 3, //! �^�b�`�p�l���h���b�O�� 29 SM_MESSAGE_PAD_UPDATE = 4, //! �p�b�h�X�V�� 30 SM_MESSAGE_SCENE_UPDATE = 5, //! �V�[���X�V�� 31 SM_MESSAGE_UPDATE_PARAM = 6 //! �X�V�ʒm 32 }; 33 typedef u32 SmMessageType; 34 35 //------------------------------------------------------------------------------ 36 // ���b�Z�[�W�N���X 37 class SmMessage : public SmBase 38 { 39 public: 40 41 // �R���X�g���N�^ SmMessage(SmMessage * parent)42 SmMessage( SmMessage* parent ) 43 : m_Parent( parent ), 44 m_Child( NULL ), 45 m_Next( NULL ), 46 m_Enable( true ), 47 m_Visible( true ), 48 m_Target( NULL ), 49 m_Id( 0 ){} 50 51 // ���b�Z�[�W�M���� 52 virtual bool SendMessage( SmMessageType type, 53 void* object = NULL, 54 uint targetId = 0 ) 55 { 56 bool ret = false; 57 58 // ���g������ 59 if ( m_Enable ) 60 { 61 if ( this->ReceveMessage( type, object, targetId ) ) 62 { 63 return true; 64 } 65 } 66 67 // �q������ΐ��� 68 if ( m_Enable && m_Child ) 69 { 70 ret = m_Child->sendMessageSub( type, object, targetId ); 71 if ( ret ) return true; 72 } 73 74 return ret; 75 } 76 77 // ���b�Z�[�W����M���� 78 // true �Ō㑱�Ƀ��b�Z�[�W����M�����Ȃ� 79 virtual bool ReceveMessage( SmMessageType type, 80 void* object = NULL, 81 uint targetId = 0 ) 82 { 83 NW_UNUSED_VARIABLE(type); 84 NW_UNUSED_VARIABLE(object); 85 NW_UNUSED_VARIABLE(targetId); 86 return false; 87 } 88 89 // �^�[�Q�b�g��ݒ肷�� SetTarget(SmMessage * target,uint id)90 void SetTarget( SmMessage* target, uint id ) 91 { 92 m_Target = target; 93 m_Id = id; 94 } 95 96 // �e��ݒ肷�� SetParent(SmMessage * parent)97 void SetParent( SmMessage* parent ) 98 { 99 m_Parent = parent; 100 } 101 102 // �e���擾���� GetParent()103 SmMessage* GetParent() 104 { 105 return m_Parent; 106 } 107 108 // �q����lj����� AddChild(SmMessage * child)109 void AddChild( SmMessage* child ) 110 { 111 child->SetParent( this ); 112 113 if ( !m_Child ) 114 { 115 m_Child = child; 116 } 117 else 118 { 119 // �q�̍Ō��Next���擾���A 120 // ����Next�Ƃ��ēo�^���� 121 SmMessage* tmp = m_Child->getNextTail(); 122 tmp->setNext( child ); 123 } 124 } 125 126 // �e�`�揈�����s�� Render()127 virtual void Render(){ return; } 128 129 // �S�Ẵc���[�̕`����s�� DrawTree()130 void DrawTree() 131 { 132 // ���g������ 133 if ( m_Visible ) 134 { 135 this->Render(); 136 } 137 138 // �Z������� 139 SmMessage* next = this->getNext(); 140 while( next ) 141 { 142 if ( next->m_Visible ) 143 { 144 next->Render(); 145 146 if ( next->m_Child ) 147 { 148 next->m_Child->DrawTree(); 149 } 150 } 151 next = next->getNext(); 152 } 153 154 // �q������ΐ��� 155 if ( m_Visible && m_Child ) 156 { 157 m_Child->DrawTree(); 158 } 159 } 160 161 // �L��/���� SetEnable(bool enable)162 void SetEnable( bool enable ) 163 { 164 // ���g������ 165 m_Enable = enable; 166 { 167 SetVisible( m_Enable ); 168 } 169 170 // �q������ΐ��� 171 if ( m_Child ) 172 { 173 m_Child->setEnableFunc( enable ); 174 } 175 176 return; 177 } 178 GetEnable()179 bool GetEnable() 180 { 181 return m_Enable; 182 } 183 SetVisible(bool visible)184 virtual void SetVisible( bool visible ) 185 { 186 m_Visible = visible; 187 } 188 189 private: sendMessageSub(SmMessageType type,void * object,uint targetId)190 bool sendMessageSub( SmMessageType type, 191 void* object, 192 uint targetId ) 193 { 194 bool ret = false; 195 196 // ���g������ 197 if ( m_Enable ) 198 { 199 if ( this->ReceveMessage( type, object, targetId ) ) 200 { 201 return true; 202 } 203 } 204 205 // �Z������� 206 SmMessage* next = this->getNext(); 207 while( next ) 208 { 209 if ( next->m_Enable ) 210 { 211 ret = next->ReceveMessage( type, object, targetId ); 212 if ( ret ) return true; 213 214 if ( next->m_Child ) 215 { 216 ret = next->m_Child->sendMessageSub( type, object, targetId ); 217 if ( ret ) return true; 218 } 219 } 220 next = next->getNext(); 221 } 222 223 // �q������ΐ��� 224 if ( m_Enable && m_Child ) 225 { 226 ret = m_Child->sendMessageSub( type, object, targetId ); 227 if ( ret ) return true; 228 } 229 230 return ret; 231 } 232 setEnableFunc(bool enable)233 void setEnableFunc( bool enable ) 234 { 235 // ���g������ 236 m_Enable = enable; 237 { 238 SetVisible( m_Enable ); 239 } 240 241 // �Z������� 242 SmMessage* next = this->getNext(); 243 while( next ) 244 { 245 next->setEnableFunc( enable ); 246 next = next->getNext(); 247 } 248 249 // �q������ΐ��� 250 if ( m_Child ) 251 { 252 m_Child->setEnableFunc( enable ); 253 } 254 255 return; 256 } 257 setNext(SmMessage * next)258 void setNext( SmMessage* next ) 259 { 260 m_Next = next; 261 } 262 getNext()263 SmMessage* getNext() 264 { 265 return m_Next; 266 } 267 getNextTail()268 SmMessage* getNextTail() 269 { 270 if ( !m_Next ) 271 { 272 return this; 273 } 274 else 275 { 276 SmMessage* pret = this->getNext(); 277 while( pret ) 278 { 279 if ( !pret->getNext() ) break; 280 pret = pret->getNext(); 281 } 282 return pret; 283 } 284 } 285 286 287 private: 288 SmMessage* m_Parent; 289 SmMessage* m_Child; 290 SmMessage* m_Next; 291 292 bool m_Enable; 293 bool m_Visible; 294 295 protected: 296 SmMessage* m_Target; 297 uint m_Id; 298 299 }; 300 301 #endif // SM_MESSAGE_H_ 302