1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     demo_PadButton.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_DEMO_PAD_BUTTON_IMPL_H_
19 #define NW_DEMO_PAD_BUTTON_IMPL_H_
20 
21 #include <nn/types.h>
22 
23 namespace nw {
24 namespace demo {
25 namespace internal {
26 
27 //---------------------------------------------------------------------------
28 //! @brief        パッドのボタン状態を管理するクラスです。
29 //---------------------------------------------------------------------------
30 class PadButton
31 {
32   public:
33     static const int BUTTON_COUNT_MAX = 32; //!< ボタンを表すビットフラグの桁数の最大値です。
34     static const int REPEAT_START = 25;     //!< キーリピート開始までのフレーム数です。
35     static const int REPEAT_SPAN  = 6;      //!< キーリピートの間隔フレーム数です。
36 
37     //! @brief コンストラクタです。
38     //!
39     PadButton();
40 
41     //! @brief パッド状態を更新します。
42     //!        前回の状態と比較して、DownやRepeatのフラグを立てます。
43     //!
44     //! @param[in]   buttonStatus  ボタンが押されている状態を表すビットフラグです。
45     //!
46     void Update( u32 buttonStatus );
47 
48     //! @brief 押されている状態はそのままに、
49     //!        DownやRepeatのフラグのみ落とします。
50     //!
51     void ClearTriggerFlag();
52 
53     //! @brief パッドの状態を初期状態にします。
54     //!        次回Update時に、ボタンが押されていても、
55     //!        DownやRepeatのフラグは立ちません。
56     //!
57     void Reset();
58 
IsButtonPress(u32 buttonBit)59     bool IsButtonPress( u32 buttonBit ) const { return ( m_ButtonPress & buttonBit ) != 0; }
IsButtonDown(u32 buttonBit)60     bool IsButtonDown( u32 buttonBit ) const { return ( m_ButtonDown & buttonBit ) != 0; }
IsButtonUp(u32 buttonBit)61     bool IsButtonUp( u32 buttonBit ) const { return ( m_ButtonUp & buttonBit ) != 0; }
IsButtonRepeat(u32 buttonBit)62     bool IsButtonRepeat( u32 buttonBit ) const { return ( m_ButtonRepeat & buttonBit ) != 0; }
IsButtonRepeatFast(u32 buttonBit)63     bool IsButtonRepeatFast( u32 buttonBit ) const { return ( m_ButtonRepeatFast & buttonBit ) != 0; }
64 
65   private:
66     u32 m_ButtonPress;
67     u32 m_ButtonDown;
68     u32 m_ButtonUp;
69     u32 m_ButtonRepeat;
70     u32 m_ButtonRepeatFast;
71     u8 m_RepeatCounter[ BUTTON_COUNT_MAX ];
72     u8 m_RepeatCounterFast[ BUTTON_COUNT_MAX ];
73     bool m_ResetFlag;
74     u8 padding[3];
75 };
76 
77 } // namespace nw::demo::internal
78 } // namespace nw::demo
79 } // namespace nw
80 
81 #endif /* NW_DEMO_PAD_BUTTON_IMPL_H_ */
82 
83