/*---------------------------------------------------------------------------* Project: NintendoWare File: SmLytButton.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 1 $ *---------------------------------------------------------------------------*/ #include #include #include #include "../include/SmLytButton.h" #include "../include/SmTouchPanelStatus.h" namespace { //---------------------------------------- // コンストラクタ SmLytButton::SmLytButton( SmLayout* smLayout, const wchar_t* string, const char* bounding ) : SmMessage( NULL ), m_Layout( smLayout ), m_LastX( 0 ), m_LastY( 0 ), m_IsPressed( false ), m_IsGrab( false ), m_IsSwitch( true ) { NW_NULL_ASSERT( m_Allocator ); NW_NULL_ASSERT( m_Layout ); // コリジョン形状を登録 SmLayoutResource* layoutRes = m_Layout->GetLayoutResource(); nw::ut::Rect rectBounding = layoutRes->GetRect( bounding ); m_Collision.SetRect( rectBounding ); if ( string ) { m_Layout->SetString( string ); } #if 0 // 文字列を登録 // TextBox ペインか const nw::lyt::Pane* pane = layoutRes->GetPane("TextBox_00"); if ( nw::lyt::TextBox* pTextBox = nw::ut::DynamicCast(pane) ) { pTextBox->SetString( string ); } #endif // 初期状態 SetSwitch( m_IsSwitch ); } //---------------------------------------- // デストラクタ SmLytButton::~SmLytButton() { } //---------------------------------------- // 位置 void SmLytButton::SetPosition( f32 x, f32 y ) { m_Layout->SetPosition( x, y ); // m_Collision.SetXY( x, y ); // コリジョンの矩形を決定します。 m_Collision.SetXY( SM_LOWER_SCREEN_HALF_SIZE_W + x - m_Collision.GetWidth()/2.f, SM_LOWER_SCREEN_HALF_SIZE_H + y - m_Collision.GetHeight()/2.f ); } //---------------------------------------- // 描画 void SmLytButton::Render() { return; } //---------------------------------------- // ボタン状態を設定する void SmLytButton::SetSwitch( bool bswitch ) { m_IsSwitch = bswitch; if ( m_IsSwitch ) { m_Layout->SetAnimationNo( 0 ); } else { m_Layout->SetAnimationNo( 1 ); } } //---------------------------------------- // ボタン状態をスワップする void SmLytButton::SwapSwitch() { if ( m_IsSwitch ) { m_IsSwitch = false; m_Layout->SetAnimationNo( 1 ); } else { m_IsSwitch = true; m_Layout->SetAnimationNo( 0 ); } } //---------------------------------------- // メッセージ受信 bool SmLytButton::ReceveMessage( SmMessageType type, void* object, uint targetId ) { NW_UNUSED_VARIABLE(targetId); SmTouchPanelStatus* touchPanelStaus = NULL; switch( type ) { case SM_MESSAGE_TUCHPANEL_PRESS: { touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); // 他処理で使用中でなければ if ( !touchPanelStaus->IsGrab() ) { // コリジョン内であれば、 if ( m_Collision.CheckInner( touchPanelStaus->GetX(), touchPanelStaus->GetY() ) ) { // 掴む touchPanelStaus->Grab(); m_IsGrab = true; m_IsPressed = true; m_Layout->SetAnimationNo( 2 ); } } } break; case SM_MESSAGE_TUCHPANEL_MOTION: { touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); if ( m_IsGrab ) { m_LastX = touchPanelStaus->GetX(); m_LastY = touchPanelStaus->GetY(); // 選択中アニメを再生 m_Layout->AddAnimationFrame( 1.f ); } } break; case SM_MESSAGE_TUCHPANEL_RELEASE: { touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); // 放す if ( m_IsGrab ) { touchPanelStaus->UnGrab(); m_IsGrab = false; m_IsPressed = false; // 選択中アニメを0.fフレームに戻します。 m_Layout->SetAnimationFrame( 0.f ); // コリジョン範囲内であれば、指定されたターゲットに対してメッセージを送信します。 if ( m_Collision.CheckInner( m_LastX, m_LastY ) ) { // 状態をスワップする SwapSwitch(); // Updateを送信 if ( m_Target ) { m_Target->SendMessage( SM_MESSAGE_UPDATE_PARAM, NULL, m_Id ); } } } } break; default: break; } return 0; } } // namespace