Blender  V3.3
GHOST_EventManager.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
12 #include "GHOST_EventManager.h"
13 #include "GHOST_Debug.h"
14 #include <algorithm>
15 
17 {
18 }
19 
21 {
22  disposeEvents();
23 
24  TConsumerVector::iterator iter = m_consumers.begin();
25  while (iter != m_consumers.end()) {
26  GHOST_IEventConsumer *consumer = *iter;
27  delete consumer;
28  iter = m_consumers.erase(iter);
29  }
30 }
31 
33 {
34  return (uint32_t)m_events.size();
35 }
36 
38 {
39  uint32_t numEvents = 0;
40  TEventStack::iterator p;
41  for (p = m_events.begin(); p != m_events.end(); ++p) {
42  if ((*p)->getType() == type) {
43  numEvents++;
44  }
45  }
46  return numEvents;
47 }
48 
50 {
51  GHOST_TSuccess success;
52  GHOST_ASSERT(event, "invalid event");
53  if (m_events.size() < m_events.max_size()) {
54  m_events.push_front(event);
55  success = GHOST_kSuccess;
56  }
57  else {
58  success = GHOST_kFailure;
59  }
60  return success;
61 }
62 
64 {
65  TConsumerVector::iterator iter;
66 
67  for (iter = m_consumers.begin(); iter != m_consumers.end(); ++iter) {
68  (*iter)->processEvent(event);
69  }
70 }
71 
73 {
74  GHOST_IEvent *event = m_events.back();
75  m_events.pop_back();
76  m_handled_events.push_back(event);
77 
78  dispatchEvent(event);
79 }
80 
82 {
83  while (!m_events.empty()) {
84  dispatchEvent();
85  }
86 
87  disposeEvents();
88 }
89 
91 {
92  GHOST_TSuccess success;
93  GHOST_ASSERT(consumer, "invalid consumer");
94 
95  /* Check to see whether the consumer is already in our list. */
96  TConsumerVector::const_iterator iter = std::find(
97  m_consumers.begin(), m_consumers.end(), consumer);
98 
99  if (iter == m_consumers.end()) {
100  /* Add the consumer. */
101  m_consumers.push_back(consumer);
102  success = GHOST_kSuccess;
103  }
104  else {
105  success = GHOST_kFailure;
106  }
107  return success;
108 }
109 
111 {
112  GHOST_TSuccess success;
113  GHOST_ASSERT(consumer, "invalid consumer");
114 
115  /* Check to see whether the consumer is in our list. */
116  TConsumerVector::iterator iter = std::find(m_consumers.begin(), m_consumers.end(), consumer);
117 
118  if (iter != m_consumers.end()) {
119  /* Remove the consumer. */
120  m_consumers.erase(iter);
121  success = GHOST_kSuccess;
122  }
123  else {
124  success = GHOST_kFailure;
125  }
126  return success;
127 }
128 
130 {
131  TEventStack::iterator iter;
132  iter = m_events.begin();
133  while (iter != m_events.end()) {
134  GHOST_IEvent *event = *iter;
135  if (event->getWindow() == window) {
136  GHOST_PRINT("GHOST_EventManager::removeWindowEvents(): removing event\n");
137  /*
138  * Found an event for this window, remove it.
139  * The iterator will become invalid.
140  */
141  delete event;
142  m_events.erase(iter);
143  iter = m_events.begin();
144  }
145  else {
146  ++iter;
147  }
148  }
149 }
150 
152 {
153  TEventStack::iterator iter;
154  iter = m_events.begin();
155  while (iter != m_events.end()) {
156  GHOST_IEvent *event = *iter;
157  if ((event->getType() == type) && (!window || (event->getWindow() == window))) {
158  GHOST_PRINT("GHOST_EventManager::removeTypeEvents(): removing event\n");
159  /*
160  * Found an event of this type for the window, remove it.
161  * The iterator will become invalid.
162  */
163  delete event;
164  m_events.erase(iter);
165  iter = m_events.begin();
166  }
167  else {
168  ++iter;
169  }
170  }
171 }
172 
174 {
175  while (m_handled_events.empty() == false) {
176  GHOST_ASSERT(m_handled_events[0], "invalid event");
177  delete m_handled_events[0];
178  m_handled_events.pop_front();
179  }
180 
181  while (m_events.empty() == false) {
182  GHOST_ASSERT(m_events[0], "invalid event");
183  delete m_events[0];
184  m_events.pop_front();
185  }
186 }
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:54
#define GHOST_PRINT(x)
Definition: GHOST_Debug.h:35
GHOST_TEventType
Definition: GHOST_Types.h:169
GHOST_TSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void removeWindowEvents(GHOST_IWindow *window)
GHOST_TSuccess addConsumer(GHOST_IEventConsumer *consumer)
GHOST_TSuccess removeConsumer(GHOST_IEventConsumer *consumer)
std::deque< GHOST_IEvent * > m_handled_events
std::deque< GHOST_IEvent * > m_events
TConsumerVector m_consumers
GHOST_TSuccess pushEvent(GHOST_IEvent *event)
void removeTypeEvents(GHOST_TEventType type, GHOST_IWindow *window=NULL)
unsigned int uint32_t
Definition: stdint.h:80