Sleeping Wombat GUI  0.100
swGUI
KeyboardDevice.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include "Device.h"
9 
10 #include "KeyboardState.h"
11 #include "InputDeviceInfo.h"
12 #include "InputDeviceEvent.h"
13 
14 #include "EventQueue.h"
15 
16 #include <queue>
17 
18 
19 namespace sw {
20 namespace input
21 {
22 
23 
40 class KeyboardDevice : public Device
41 {
42 private:
43 
46 
48 
49 protected:
50 public:
51  explicit KeyboardDevice () = default;
52  ~KeyboardDevice () = default;
53 
54 
55  const InputDeviceInfo& GetInfo () const { return m_info; }
56  const KeyboardState& GetState () const { return m_state; }
57 
59 
60  void ApplyAllEvents ();
63 
64  void RemoveEvents ();
65 
66 public:
67 
70 
73  void AddEvent ( const DeviceEvent& event );
74 
76 
77 };
78 
79 DEFINE_OPTR_TYPE( KeyboardDevice );
80 
81 //====================================================================================//
82 // Inline implementation
83 //====================================================================================//
84 
85 
86 // ================================ //
87 //
89 {
90  while( !m_events.NoMoreEvents() )
91  {
92  auto& event = m_events.PopEvent();
93 
94  // Characters don't influence KeyboardState.
95  if( event.Type == DeviceEventType::KeyboardEvent )
96  m_state.ApplyEvent( event );
97  }
98 }
99 
100 // ================================ //
101 //
103 {
104  if( m_events.NoMoreEvents() )
105  return DeviceEvent();
106 
107 
108  auto& nextEvent = m_events.PopEvent();
109  m_state.ApplyEvent( nextEvent );
110 
111  return nextEvent;
112 }
113 
114 // ================================ //
115 //
117 {
118  return m_events.FrontEvent().LogicalTime;
119 }
120 
121 // ================================ //
122 //
124 {
126  m_events.ClearReadEvents();
127 }
128 
129 
130 // ================================ //
131 //
132 inline void KeyboardDevice::AddEvent ( const DeviceEvent& event )
133 {
134  m_events.AddEvent( event );
135 }
136 
137 
138 } // input
139 } // sw
140 
EventQueue< DeviceEvent > & GetEventsQueue()
Definition: KeyboardDevice.h:58
Information about device. For future use.
Definition: InputDeviceInfo.h:14
uint16 Timestamp
Definition: InputDeviceEvent.h:19
Timestamp GetNextEvtTimestamp()
Definition: KeyboardDevice.h:116
DeviceEvent ApplyNextEvent()
Definition: KeyboardDevice.h:102
Definition: DirectInputModule.cpp:11
void RemoveEvents()
Removes information about pressed or unpressed buttons. Key states remain unchanged.
Definition: KeyboardState.h:71
EventQueue< DeviceEvent > m_events
Definition: KeyboardDevice.h:47
KeyStates changed events.
Definition: InputDeviceEvent.h:313
void AddEvent(const DeviceEvent &event)
Add event to event queue. This function doesn't change KeyboardState.
Definition: KeyboardDevice.h:132
InputDeviceInfo m_info
Definition: KeyboardDevice.h:44
void RemoveEvents()
Definition: KeyboardDevice.h:123
const InputDeviceInfo & GetInfo() const
Definition: KeyboardDevice.h:55
Keyboard state and events.
Definition: KeyboardDevice.h:40
void ApplyAllEvents()
Definition: KeyboardDevice.h:88
Interface class for input devices.
Definition: Device.h:21
State of keyboard buttons.
Definition: KeyboardState.h:26
void ApplyEvent(const DeviceEvent &event)
Sets state depending on event.
Definition: KeyboardState.h:80
Abstraction of event queue.
Definition: EventQueue.h:26
KeyboardState m_state
Definition: KeyboardDevice.h:45
DEFINE_OPTR_TYPE(Device)
const KeyboardState & GetState() const
Definition: KeyboardDevice.h:56