1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: SmSliderBar.cpp
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
13 $Revision: 1 $
14 *---------------------------------------------------------------------------*/
15
16 #include "../include/SmLytSliderBar.h"
17 #include "../include/SmTouchPanelStatus.h"
18
19 namespace
20 {
21
22 //----------------------------------------
23 // コンストラクタ
SmLytSliderBar(f32 x,f32 y,SmLayout * smLayout)24 SmLytSliderBar::SmLytSliderBar( f32 x, f32 y, SmLayout* smLayout )
25 : SmMessage( NULL ),
26 m_Layout( smLayout ),
27 m_HandlePane( NULL ),
28 m_Param( 0.0f ),
29 m_IsGrab( false ),
30 m_RangeMinY( 0 ),
31 m_RangeMaxY( 0 ),
32 m_BaseY( y )
33 {
34 NW_NULL_ASSERT( m_Layout );
35
36 SmLayoutResource* layoutRes = m_Layout->GetLayoutResource();
37 nw::ut::Rect rectBase = layoutRes->GetRect( "SliderBase" );
38 nw::ut::Rect rectHandle = layoutRes->GetRect( "SliderBounding" );
39 m_HandlePane = layoutRes->GetPane( "SliderHandle00" );
40
41 m_Collision.SetRect( rectHandle );
42
43 m_Layout->SetPosition( x, y );
44
45 // コリジョンの矩形を決定します。
46 m_Collision.SetXY( SM_LOWER_SCREEN_HALF_SIZE_W + x - m_Collision.GetWidth()/2.f,
47 SM_LOWER_SCREEN_HALF_SIZE_H + y - m_Collision.GetHeight()/2.f );
48
49 // ハンドルの上限下限値を求めます。
50 m_RangeMinY = SM_LOWER_SCREEN_HALF_SIZE_H + y - rectBase.GetHeight()/2.f;
51 m_RangeMaxY = SM_LOWER_SCREEN_HALF_SIZE_H + y + rectBase.GetHeight()/2.f;
52
53 // パラメータを初期化し、ハンドルとコリジョンを更新します。
54 m_Param = 0.0f;
55 SetParam( m_Param );
56 }
57
58
59 //----------------------------------------
60 // デストラクタ
~SmLytSliderBar()61 SmLytSliderBar::~SmLytSliderBar()
62 {
63
64 }
65
66
67 //----------------------------------------
68 // 描画
Render()69 void SmLytSliderBar::Render()
70 {
71 return;
72 }
73
74
75 //----------------------------------------
76 // パラメータ値をセットする
SetParam(f32 param)77 void SmLytSliderBar::SetParam( f32 param )
78 {
79 if ( param < 0.0f ) return;
80 if ( param > 1.0f ) return;
81
82 s32 posY = ( m_RangeMaxY - m_RangeMinY ) * param + m_RangeMinY;
83
84 // ハンドルの表示位置を更新
85 m_Layout->SetPanePosition( m_HandlePane, 0.f, SM_LOWER_SCREEN_HALF_SIZE_H - posY + m_BaseY );
86
87 // コリジョンを更新
88 m_Collision.SetXY( m_Collision.GetX(), posY - m_Collision.GetHeight()/2.f );
89
90 // todo
91 m_Param = param;
92 }
93
94
95 //----------------------------------------
96 // メッセージ受信
ReceveMessage(SmMessageType type,void * object,uint targetId)97 bool SmLytSliderBar::ReceveMessage( SmMessageType type, void* object, uint targetId )
98 {
99 NW_UNUSED_VARIABLE(targetId);
100
101 SmTouchPanelStatus* touchPanelStaus = NULL;
102
103 switch( type )
104 {
105 case SM_MESSAGE_TUCHPANEL_PRESS:
106 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
107 NW_NULL_ASSERT( touchPanelStaus );
108
109 if ( m_Collision.CheckInner( touchPanelStaus->GetX(), touchPanelStaus->GetY() ) )
110 {
111 if ( !touchPanelStaus->IsGrab() )
112 {
113 touchPanelStaus->Grab();
114 m_IsGrab = true;
115 }
116 }
117 break;
118
119 case SM_MESSAGE_TUCHPANEL_RELEASE:
120 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
121 NW_NULL_ASSERT( touchPanelStaus );
122
123 if ( m_IsGrab )
124 {
125 touchPanelStaus->UnGrab();
126 m_IsGrab = false;
127 }
128 break;
129
130
131 case SM_MESSAGE_TUCHPANEL_MOTION:
132 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
133 NW_NULL_ASSERT( touchPanelStaus );
134
135 if ( m_IsGrab )
136 {
137 // オフセットを求める
138 s32 currentY = touchPanelStaus->GetY();
139
140 // 制限
141 if ( currentY < m_RangeMinY ) currentY = m_RangeMinY;
142 if ( m_RangeMaxY < currentY ) currentY = m_RangeMaxY;
143
144 // パラメータを計算しセットします。
145 m_Param = static_cast<f32>( currentY - m_RangeMinY );
146 m_Param /= static_cast<f32>( m_RangeMaxY - m_RangeMinY );
147 SetParam( m_Param );
148
149 // ターゲットに更新メッセージを送信します。
150 if ( m_Target )
151 {
152 m_Target->SendMessage( SM_MESSAGE_UPDATE_PARAM, NULL, m_Id );
153 }
154 }
155 break;
156
157 }
158
159 return 0;
160 }
161
162 } // namespace
163
164
165