Sleeping Wombat GUI  0.100
swGUI
KeyState.h
Go to the documentation of this file.
1 #pragma once
2 
11 
12 #include <assert.h>
13 
14 
15 
16 
17 namespace sw {
18 namespace input
19 {
20 
21 
22 
26 class KeyState
27 {
29  {
30  Pressed = 0x1,
31  DownEvent = 0x2,
32  UpEvent = 0x4
33  };
34 
35 private:
36 
38 
39 public:
40 
41  explicit KeyState()
42  : m_state( 0 )
43  {}
44 
45  inline bool IsPressed () const { return ( m_state & Pressed ) != 0; }
46  inline bool IsUp () const { return !IsPressed(); }
47 
48  inline bool IsKeyDownEvent () const { return ( m_state & DownEvent ) != 0; }
49  inline bool IsKeyUpEvent () const { return ( m_state & UpEvent ) != 0; }
50 
52  inline operator void* ( ) const { return (void*)IsPressed(); }
53 
54  inline void operator= ( KeyState newState )
55  {
56  m_state = newState.m_state;
57  }
58 
59 public:
62  inline void Press () { m_state = Pressed | DownEvent; }
63  inline void UnPress () { m_state = UpEvent; }
64  inline void HoldState () { m_state = m_state & Pressed; }
65 
66  inline void operator= ( bool newState )
67  {
68  if( !IsPressed() && newState )
69  Press();
70  else if( IsPressed() && !newState )
71  UnPress();
72  else
73  HoldState();
74  }
76 };
77 
78 
79 } // input
80 } // sw
81 
bool IsKeyDownEvent() const
Definition: KeyState.h:48
Definition: KeyState.h:31
int8_t int8
Definition: TypesDefinitions.h:26
Definition: DirectInputModule.cpp:11
void operator=(KeyState newState)
Definition: KeyState.h:54
void Press()
Wciska przycisk.
Definition: KeyState.h:62
bool IsUp() const
Definition: KeyState.h:46
Plik zawiera definicje podstawowych typów zmiennych.
int8 m_state
Definition: KeyState.h:37
bool IsKeyUpEvent() const
Definition: KeyState.h:49
Definition: KeyState.h:32
KeyStateFlag
Definition: KeyState.h:28
KeyState()
Definition: KeyState.h:41
Button state structure..
Definition: KeyState.h:26
void HoldState()
Podtrzymuje stan przycisku i kasuje info o eventach.
Definition: KeyState.h:64
bool IsPressed() const
Definition: KeyState.h:45
Definition: KeyState.h:30
void UnPress()
Puszcza przycisk.
Definition: KeyState.h:63