/*---------------------------------------------------------------------------* Project: NintendoWare File: SmLytSliderBar.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #include "../include/SmLytSliderBar.h" #include "../include/SmTouchPanelStatus.h" namespace { //---------------------------------------- // コンストラクタ SmLytSliderBar::SmLytSliderBar( f32 x, f32 y, SmLayout* smLayout ) : SmMessage( NULL ), m_Layout( smLayout ), m_HandlePane( NULL ), m_Param( 0.0f ), m_IsGrab( false ), m_RangeMinY( 0 ), m_RangeMaxY( 0 ), m_BaseY( y ) { NW_NULL_ASSERT( m_Layout ); SmLayoutResource* layoutRes = m_Layout->GetLayoutResource(); nw::ut::Rect rectBase = layoutRes->GetRect( "SliderBase" ); nw::ut::Rect rectHandle = layoutRes->GetRect( "SliderBounding" ); m_HandlePane = layoutRes->GetPane( "SliderHandle00" ); m_Collision.SetRect( rectHandle ); m_Layout->SetPosition( 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 ); // ハンドルの上限下限値を求めます。 m_RangeMinY = SM_LOWER_SCREEN_HALF_SIZE_H + y - rectBase.GetHeight()/2.f; m_RangeMaxY = SM_LOWER_SCREEN_HALF_SIZE_H + y + rectBase.GetHeight()/2.f; // パラメータを初期化し、ハンドルとコリジョンを更新します。 m_Param = 0.0f; SetParam( m_Param ); } //---------------------------------------- // デストラクタ SmLytSliderBar::~SmLytSliderBar() { } //---------------------------------------- // 描画 void SmLytSliderBar::Render() { return; } //---------------------------------------- // パラメータ値をセットする void SmLytSliderBar::SetParam( f32 param ) { if ( param < 0.0f ) return; if ( param > 1.0f ) return; s32 posY = ( m_RangeMaxY - m_RangeMinY ) * param + m_RangeMinY; // ハンドルの表示位置を更新 m_Layout->SetPanePosition( m_HandlePane, 0.f, SM_LOWER_SCREEN_HALF_SIZE_H - posY + m_BaseY ); // コリジョンを更新 m_Collision.SetXY( m_Collision.GetX(), posY - m_Collision.GetHeight()/2.f ); // todo m_Param = param; } //---------------------------------------- // メッセージ受信 bool SmLytSliderBar::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 ( m_Collision.CheckInner( touchPanelStaus->GetX(), touchPanelStaus->GetY() ) ) { if ( !touchPanelStaus->IsGrab() ) { touchPanelStaus->Grab(); m_IsGrab = true; } } break; case SM_MESSAGE_TUCHPANEL_RELEASE: touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); if ( m_IsGrab ) { touchPanelStaus->UnGrab(); m_IsGrab = false; } break; case SM_MESSAGE_TUCHPANEL_MOTION: touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); if ( m_IsGrab ) { // オフセットを求める s32 currentY = touchPanelStaus->GetY(); // 制限 if ( currentY < m_RangeMinY ) currentY = m_RangeMinY; if ( m_RangeMaxY < currentY ) currentY = m_RangeMaxY; // パラメータを計算しセットします。 m_Param = static_cast( currentY - m_RangeMinY ); m_Param /= static_cast( m_RangeMaxY - m_RangeMinY ); SetParam( m_Param ); // ターゲットに更新メッセージを送信します。 if ( m_Target ) { m_Target->SendMessage( SM_MESSAGE_UPDATE_PARAM, NULL, m_Id ); } } break; } return 0; } } // namespace