Przeglądaj źródła

minor event refinements

David Rose 23 lat temu
rodzic
commit
81b7084fca

+ 14 - 0
panda/src/event/eventQueue.cxx

@@ -68,6 +68,20 @@ queue_event(CPT_Event event) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EventQueue::clear
+//       Access: Public
+//  Description: Empties all events on the queue, throwing them on the
+//               floor.
+////////////////////////////////////////////////////////////////////
+void EventQueue::
+clear() {
+  while (!_queue.empty()) {
+    _queue.pop_front();
+  }
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EventQueue::is_queue_empty
 //       Access: Public

+ 1 - 1
panda/src/event/eventQueue.h

@@ -46,7 +46,7 @@ PUBLISHED:
   ~EventQueue();
 
   void queue_event(CPT_Event event);
-
+  void clear();
 
   bool is_queue_empty() const;
   bool is_queue_full() const;

+ 13 - 4
panda/src/framework/pandaFramework.cxx

@@ -966,10 +966,19 @@ event_window_event(CPT_Event event, void *data) {
     const GraphicsWindow *win;
     DCAST_INTO_V(win, param.get_ptr());
 
-    if (!win->get_properties().get_open()) {
-      // If the last window was closed, exit the application.
-      if (self->all_windows_closed()) {
-        self->_exit_flag = true;
+    // Is this a window we've heard about?
+    int window_index = self->find_window(win);
+    if (window_index == -1) {
+      framework_cat.warning()
+        << "Ignoring message from unknown window.\n";
+    } else {
+      if (!win->get_properties().get_open()) {
+        // If the last window was closed, exit the application.
+        if (self->all_windows_closed() && !self->_exit_flag) {
+          framework_cat.info()
+            << "Last window was closed by user.\n";
+          self->_exit_flag = true;
+        }
       }
     }
   }