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( "slider_base_00" );
38 nw::ut::Rect rectHandle = layoutRes->GetRect( "slider_Bounding" );
39 m_HandlePane = layoutRes->GetPane( "slider_handle_00" );
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 // パラメータを初期化し、ハンドルとコリジョンを更新します。
55 m_Param = 0.0f;
56 SetParam( m_Param );
57 }
58
59
60 //----------------------------------------
61 // デストラクタ
~SmLytSliderBar()62 SmLytSliderBar::~SmLytSliderBar()
63 {
64
65 }
66
67
68 //----------------------------------------
69 // 描画
Render()70 void SmLytSliderBar::Render()
71 {
72 return;
73 }
74
75
76 //----------------------------------------
77 // パラメータ値をセットする
SetParam(f32 param)78 void SmLytSliderBar::SetParam( f32 param )
79 {
80 if ( param < 0.0f ) return;
81 if ( param > 1.0f ) return;
82
83 s32 posY = ( m_RangeMaxY - m_RangeMinY ) * param + m_RangeMinY;
84
85 // ハンドルの表示位置を更新
86 m_Layout->SetPanePosition( m_HandlePane, 0.f, SM_LOWER_SCREEN_HALF_SIZE_H - posY + m_BaseY );
87
88 // コリジョンを更新
89 m_Collision.SetXY( m_Collision.GetX(), posY - m_Collision.GetHeight()/2.f );
90
91 // todo
92 m_Param = param;
93 }
94
95
96 //----------------------------------------
97 // メッセージ受信
ReceveMessage(SmMessageType type,void * object,uint targetId)98 bool SmLytSliderBar::ReceveMessage( SmMessageType type, void* object, uint targetId )
99 {
100 NW_UNUSED_VARIABLE(targetId);
101
102 SmTouchPanelStatus* touchPanelStaus = NULL;
103
104 switch( type )
105 {
106 case SM_MESSAGE_TUCHPANEL_PRESS:
107 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
108 NW_NULL_ASSERT( touchPanelStaus );
109
110 if ( m_Collision.CheckInner( touchPanelStaus->GetX(), touchPanelStaus->GetY() ) )
111 {
112 if ( !touchPanelStaus->IsGrab() )
113 {
114 touchPanelStaus->Grab();
115 m_IsGrab = true;
116 }
117 }
118 break;
119
120 case SM_MESSAGE_TUCHPANEL_RELEASE:
121 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
122 NW_NULL_ASSERT( touchPanelStaus );
123
124 if ( m_IsGrab )
125 {
126 touchPanelStaus->UnGrab();
127 m_IsGrab = false;
128 }
129 break;
130
131
132 case SM_MESSAGE_TUCHPANEL_MOTION:
133 touchPanelStaus = static_cast<SmTouchPanelStatus*>(object);
134 NW_NULL_ASSERT( touchPanelStaus );
135
136 if ( m_IsGrab )
137 {
138 // オフセットを求める
139 s32 currentY = touchPanelStaus->GetY();
140
141 // 制限
142 if ( currentY < m_RangeMinY ) currentY = m_RangeMinY;
143 if ( m_RangeMaxY < currentY ) currentY = m_RangeMaxY;
144
145 // パラメータを計算しセットします。
146 m_Param = static_cast<f32>( currentY - m_RangeMinY );
147 m_Param /= static_cast<f32>( m_RangeMaxY - m_RangeMinY );
148 SetParam( m_Param );
149
150 // ターゲットに更新メッセージを送信します。
151 if ( m_Target )
152 {
153 m_Target->SendMessage( SM_MESSAGE_UPDATE_PARAM, NULL, m_Id );
154 }
155 }
156 break;
157
158 }
159
160 return 0;
161 }
162
163 } // namespace
164
165
166