Sleeping Wombat GUI  0.100
swGUI
MouseDevice.h
Go to the documentation of this file.
1 #pragma once
2 
8 #include "Device.h"
9 
10 #include "MouseState.h"
11 #include "InputDeviceInfo.h"
12 #include "InputDeviceEvent.h"
13 
14 #include "EventQueue.h"
15 
16 #include <vector>
17 
18 
19 namespace sw {
20 namespace input
21 {
22 
23 
27 class MouseDevice : public Device
28 {
29 private:
30 
33 
35 
36 protected:
37 public:
38  explicit MouseDevice () = default;
39  ~MouseDevice () = default;
40 
41 
42  const InputDeviceInfo& GetInfo () const { return m_info; }
43  const MouseState& GetState () const { return m_state; }
44 
46 
47  void ApplyAllEvents ();
50 
51  void RemoveEvents ();
52 
53 public:
56 
59  void AddEvent ( const DeviceEvent& event );
60 
62 };
63 
64 
65 DEFINE_OPTR_TYPE( MouseDevice );
66 
67 //====================================================================================//
68 // Inline implementation
69 //====================================================================================//
70 
71 // ================================ //
72 //
74 {
75  while( !m_events.NoMoreEvents() )
76  {
77  auto& event = m_events.PopEvent();
78  m_state.ApplyEvent( event );
79  }
80 }
81 
82 // ================================ //
83 //
85 {
86  if( m_events.NoMoreEvents() )
87  return DeviceEvent();
88 
89  auto& nextEvent = m_events.PopEvent();
90  m_state.ApplyEvent( nextEvent );
91 
92  return nextEvent;
93 }
94 
95 // ================================ //
96 //
98 {
99  if( m_events.NoMoreEvents() )
100  return std::numeric_limits< Timestamp >::max();
101 
102  return m_events.FrontEvent().LogicalTime;
103 }
104 
105 // ================================ //
106 //
108 {
110  m_events.ClearReadEvents();
111 }
112 
113 
114 // ================================ //
115 //
116 inline void MouseDevice::AddEvent ( const DeviceEvent& event )
117 {
118  m_events.AddEvent( event );
119 }
120 
121 
122 
123 
124 } // input
125 } // sw
126 
127 
Information about device. For future use.
Definition: InputDeviceInfo.h:14
void RemoveEvents()
Definition: MouseDevice.h:107
uint16 Timestamp
Definition: InputDeviceEvent.h:19
State of mouse.
Definition: MouseState.h:27
const InputDeviceInfo & GetInfo() const
Definition: MouseDevice.h:42
Timestamp GetNextEvtTimestamp()
Definition: MouseDevice.h:97
void ApplyAllEvents()
Definition: MouseDevice.h:73
InputDeviceInfo m_info
Definition: MouseDevice.h:31
Definition: DirectInputModule.cpp:11
const MouseState & GetState() const
Definition: MouseDevice.h:43
KeyStates changed events.
Definition: InputDeviceEvent.h:313
MouseState m_state
Definition: MouseDevice.h:32
void AddEvent(const DeviceEvent &event)
Add event to event queue. This function doesn't change KeyboardState.
Definition: MouseDevice.h:116
void ApplyEvent(const ButtonEvent &event)
Updates state depending on event.
Definition: MouseState.h:107
void RemoveEvents()
Czyści tablicę z eventów o wciśnięciu klawiszy, ale podtrzymuje stan przycisków.
Definition: MouseState.h:99
Interface class for input devices.
Definition: Device.h:21
EventQueue< DeviceEvent > & GetEventsQueue()
Definition: MouseDevice.h:45
EventQueue< DeviceEvent > m_events
Definition: MouseDevice.h:34
Mouse state and events.
Definition: MouseDevice.h:27
Abstraction of event queue.
Definition: EventQueue.h:26
DEFINE_OPTR_TYPE(Device)
DeviceEvent ApplyNextEvent()
Definition: MouseDevice.h:84