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