/*---------------------------------------------------------------------------* Project: NintendoWare File: SmSliderBar.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 #include #include "../include/SmSliderBar.h" #include "../include/SmTouchPanelStatus.h" namespace { #define SM_BAR_HALF_SIZE (8.f) #define SM_SLIDER_COL_HALF_SIZE (10.f) #define SM_SLIDER_HALF_SIZE (8.f) //---------------------------------------- // コンストラクタ SmSliderBar::SmSliderBar( uint x, uint y, uint length, SmSliderBarType type ) : SmMessage( NULL ), m_SliderType( type ), m_Bar( NULL ), m_Slider( NULL ), m_Length( length ), m_IsGrab( false ), m_BaseX( x ), m_BaseY( y ), m_GrabX( 0 ), m_GrabY( 0 ), m_OffsetX( 0 ), m_OffsetY( 0 ), m_PreOffsetX( 0 ), m_PreOffsetY( 0 ) { NW_NULL_ASSERT( m_Allocator ); // Barポリゴン生成 m_Bar = new Sm2DPrimPC( 4 ); NW_NULL_ASSERT( m_Bar ); { m_Bar->SetVertex( 0, x - SM_BAR_HALF_SIZE, y, nw::ut::Color8::BLACK ); m_Bar->SetVertex( 1, x - SM_BAR_HALF_SIZE, y + length, nw::ut::Color8::BLACK ); m_Bar->SetVertex( 2, x + SM_BAR_HALF_SIZE, y, nw::ut::Color8::BLACK ); m_Bar->SetVertex( 3, x + SM_BAR_HALF_SIZE, y + length, nw::ut::Color8::BLACK ); } m_Bar->Update(); // Sliderポリゴン生成 m_Slider = new Sm2DPrimPC( 4 ); NW_NULL_ASSERT( m_Bar ); { m_Slider->SetVertex( 0, x - SM_SLIDER_HALF_SIZE, y - SM_SLIDER_HALF_SIZE, nw::ut::Color8::RED ); m_Slider->SetVertex( 1, x - SM_SLIDER_HALF_SIZE, y + SM_SLIDER_HALF_SIZE, nw::ut::Color8::RED ); m_Slider->SetVertex( 2, x + SM_SLIDER_HALF_SIZE, y - SM_SLIDER_HALF_SIZE, nw::ut::Color8::RED ); m_Slider->SetVertex( 3, x + SM_SLIDER_HALF_SIZE, y + SM_SLIDER_HALF_SIZE, nw::ut::Color8::RED ); } // ユニフォーム(オフセット)の値がキャッシュと合わないので、キャッシュを生成しない // m_Slider->Update(); // コリジョン形状を登録 m_Collision.SetRect( x - SM_SLIDER_COL_HALF_SIZE, y - SM_SLIDER_COL_HALF_SIZE, SM_SLIDER_COL_HALF_SIZE * 2.f, SM_SLIDER_COL_HALF_SIZE * 2.f ); } //---------------------------------------- // デストラクタ SmSliderBar::~SmSliderBar() { if( m_Bar ) delete m_Bar; m_Bar = NULL; if( m_Slider ) delete m_Slider; m_Slider = NULL; } //---------------------------------------- // 描画 void SmSliderBar::Render() { m_Bar->Render( GL_TRIANGLE_STRIP ); m_Slider->Render( GL_TRIANGLE_STRIP, static_cast(m_OffsetX), static_cast(m_OffsetY) ); } //---------------------------------------- // メッセージ受信 bool SmSliderBar::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; // 掴んだ位置 m_GrabX = touchPanelStaus->GetX(); m_GrabY = touchPanelStaus->GetY(); } } break; case SM_MESSAGE_TUCHPANEL_RELEASE: touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); // 放す if( m_IsGrab ) { touchPanelStaus->UnGrab(); m_IsGrab = false; m_PreOffsetX = m_OffsetX; m_PreOffsetY = m_OffsetY; } break; case SM_MESSAGE_TUCHPANEL_MOTION: touchPanelStaus = static_cast(object); NW_NULL_ASSERT( touchPanelStaus ); // 差分を計算し、制限をかける if( m_IsGrab ) { // オフセットを求める m_OffsetX = 0;//m_GrabX + static_cast( touchPanelStaus->GetX() ); m_OffsetY = static_cast( touchPanelStaus->GetY() ) - m_GrabY + m_PreOffsetY; // 制限 if( m_OffsetY <= 0 ) m_OffsetY = 0; if( m_Length < m_OffsetY ) m_OffsetY = m_Length; // コリジョン側も更新 m_Collision.SetXY( m_BaseX + m_OffsetX - SM_SLIDER_COL_HALF_SIZE, m_BaseY + m_OffsetY - SM_SLIDER_COL_HALF_SIZE ); // Updateを送信 if( m_Target ) { m_Target->SendMessage( SM_MESSAGE_UPDATE_PARAM, NULL, m_Id ); } } break; } return 0; } } // namespace