Blender  V2.93
GHOST_EventManager.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
28 #include "GHOST_EventManager.h"
29 #include "GHOST_Debug.h"
30 #include <algorithm>
31 #include <stdio.h> // [mce] temp debug
32 
34 {
35 }
36 
38 {
39  disposeEvents();
40 
41  TConsumerVector::iterator iter = m_consumers.begin();
42  while (iter != m_consumers.end()) {
43  GHOST_IEventConsumer *consumer = *iter;
44  delete consumer;
45  iter = m_consumers.erase(iter);
46  }
47 }
48 
50 {
51  return (GHOST_TUns32)m_events.size();
52 }
53 
55 {
56  GHOST_TUns32 numEvents = 0;
57  TEventStack::iterator p;
58  for (p = m_events.begin(); p != m_events.end(); ++p) {
59  if ((*p)->getType() == type) {
60  numEvents++;
61  }
62  }
63  return numEvents;
64 }
65 
67 {
68  GHOST_TSuccess success;
69  GHOST_ASSERT(event, "invalid event");
70  if (m_events.size() < m_events.max_size()) {
71  m_events.push_front(event);
72  success = GHOST_kSuccess;
73  }
74  else {
75  success = GHOST_kFailure;
76  }
77  return success;
78 }
79 
81 {
82  TConsumerVector::iterator iter;
83 
84  for (iter = m_consumers.begin(); iter != m_consumers.end(); ++iter) {
85  (*iter)->processEvent(event);
86  }
87 }
88 
90 {
91  GHOST_IEvent *event = m_events.back();
92  m_events.pop_back();
93  m_handled_events.push_back(event);
94 
95  dispatchEvent(event);
96 }
97 
99 {
100  while (!m_events.empty()) {
101  dispatchEvent();
102  }
103 
104  disposeEvents();
105 }
106 
108 {
109  GHOST_TSuccess success;
110  GHOST_ASSERT(consumer, "invalid consumer");
111 
112  // Check to see whether the consumer is already in our list
113  TConsumerVector::const_iterator iter = std::find(
114  m_consumers.begin(), m_consumers.end(), consumer);
115 
116  if (iter == m_consumers.end()) {
117  // Add the consumer
118  m_consumers.push_back(consumer);
119  success = GHOST_kSuccess;
120  }
121  else {
122  success = GHOST_kFailure;
123  }
124  return success;
125 }
126 
128 {
129  GHOST_TSuccess success;
130  GHOST_ASSERT(consumer, "invalid consumer");
131 
132  // Check to see whether the consumer is in our list
133  TConsumerVector::iterator iter = std::find(m_consumers.begin(), m_consumers.end(), consumer);
134 
135  if (iter != m_consumers.end()) {
136  // Remove the consumer
137  m_consumers.erase(iter);
138  success = GHOST_kSuccess;
139  }
140  else {
141  success = GHOST_kFailure;
142  }
143  return success;
144 }
145 
147 {
148  TEventStack::iterator iter;
149  iter = m_events.begin();
150  while (iter != m_events.end()) {
151  GHOST_IEvent *event = *iter;
152  if (event->getWindow() == window) {
153  GHOST_PRINT("GHOST_EventManager::removeWindowEvents(): removing event\n");
154  /*
155  * Found an event for this window, remove it.
156  * The iterator will become invalid.
157  */
158  delete event;
159  m_events.erase(iter);
160  iter = m_events.begin();
161  }
162  else {
163  ++iter;
164  }
165  }
166 }
167 
169 {
170  TEventStack::iterator iter;
171  iter = m_events.begin();
172  while (iter != m_events.end()) {
173  GHOST_IEvent *event = *iter;
174  if ((event->getType() == type) && (!window || (event->getWindow() == window))) {
175  GHOST_PRINT("GHOST_EventManager::removeTypeEvents(): removing event\n");
176  /*
177  * Found an event of this type for the window, remove it.
178  * The iterator will become invalid.
179  */
180  delete event;
181  m_events.erase(iter);
182  iter = m_events.begin();
183  }
184  else {
185  ++iter;
186  }
187  }
188 }
189 
191 {
192  while (m_handled_events.empty() == false) {
193  GHOST_ASSERT(m_handled_events[0], "invalid event");
194  delete m_handled_events[0];
195  m_handled_events.pop_front();
196  }
197 
198  while (m_events.empty() == false) {
199  GHOST_ASSERT(m_events[0], "invalid event");
200  delete m_events[0];
201  m_events.pop_front();
202  }
203 }
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:79
#define GHOST_PRINT(x)
Definition: GHOST_Debug.h:51
unsigned int GHOST_TUns32
Definition: GHOST_Types.h:64
GHOST_TEventType
Definition: GHOST_Types.h:177
GHOST_TSuccess
Definition: GHOST_Types.h:91
@ GHOST_kFailure
Definition: GHOST_Types.h:91
@ GHOST_kSuccess
Definition: GHOST_Types.h:91
_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_TUns32 getNumEvents()
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)