Browse Source

Change priority of callbacks vs plugins in the Viewer (fixes #764).

Former-commit-id: 4087099a665c3faf4c2fa01c411b5a13c219e369
Jérémie Dumas 6 years ago
parent
commit
92f2e20fa5
1 changed files with 39 additions and 37 deletions
  1. 39 37
      include/igl/opengl/glfw/Viewer.cpp

+ 39 - 37
include/igl/opengl/glfw/Viewer.cpp

@@ -477,10 +477,6 @@ namespace glfw
 
   IGL_INLINE bool Viewer::key_pressed(unsigned int unicode_key,int modifiers)
   {
-    if (callback_key_pressed)
-      if (callback_key_pressed(*this,unicode_key,modifiers))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
     {
       if (plugins[i]->key_pressed(unicode_key, modifiers))
@@ -489,6 +485,10 @@ namespace glfw
       }
     }
 
+    if (callback_key_pressed)
+      if (callback_key_pressed(*this,unicode_key,modifiers))
+        return true;
+
     switch(unicode_key)
     {
       case 'A':
@@ -563,25 +563,27 @@ namespace glfw
 
   IGL_INLINE bool Viewer::key_down(int key,int modifiers)
   {
-    if (callback_key_down)
-      if (callback_key_down(*this,key,modifiers))
-        return true;
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if (plugins[i]->key_down(key, modifiers))
         return true;
+
+    if (callback_key_down)
+      if (callback_key_down(*this,key,modifiers))
+        return true;
+
     return false;
   }
 
   IGL_INLINE bool Viewer::key_up(int key,int modifiers)
   {
-    if (callback_key_up)
-      if (callback_key_up(*this,key,modifiers))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if (plugins[i]->key_up(key, modifiers))
         return true;
 
+    if (callback_key_up)
+      if (callback_key_up(*this,key,modifiers))
+        return true;
+
     return false;
   }
 
@@ -591,14 +593,14 @@ namespace glfw
     down_mouse_x = current_mouse_x;
     down_mouse_y = current_mouse_y;
 
-    if (callback_mouse_down)
-      if (callback_mouse_down(*this,static_cast<int>(button),modifier))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if(plugins[i]->mouse_down(static_cast<int>(button),modifier))
         return true;
 
+    if (callback_mouse_down)
+      if (callback_mouse_down(*this,static_cast<int>(button),modifier))
+        return true;
+
     down = true;
 
     down_translation = core.camera_translation;
@@ -651,14 +653,14 @@ namespace glfw
   {
     down = false;
 
-    if (callback_mouse_up)
-      if (callback_mouse_up(*this,static_cast<int>(button),modifier))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if(plugins[i]->mouse_up(static_cast<int>(button),modifier))
           return true;
 
+    if (callback_mouse_up)
+      if (callback_mouse_up(*this,static_cast<int>(button),modifier))
+        return true;
+
     mouse_mode = MouseMode::None;
 
     return true;
@@ -675,14 +677,14 @@ namespace glfw
     current_mouse_x = mouse_x;
     current_mouse_y = mouse_y;
 
-    if (callback_mouse_move)
-      if (callback_mouse_move(*this,mouse_x,mouse_y))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if (plugins[i]->mouse_move(mouse_x, mouse_y))
         return true;
 
+    if (callback_mouse_move)
+      if (callback_mouse_move(*this,mouse_x,mouse_y))
+        return true;
+
     if (down)
     {
       switch (mouse_mode)
@@ -752,14 +754,14 @@ namespace glfw
   {
     scroll_position += delta_y;
 
-    if (callback_mouse_scroll)
-      if (callback_mouse_scroll(*this,delta_y))
-        return true;
-
     for (unsigned int i = 0; i<plugins.size(); ++i)
       if (plugins[i]->mouse_scroll(delta_y))
         return true;
 
+    if (callback_mouse_scroll)
+      if (callback_mouse_scroll(*this,delta_y))
+        return true;
+
     // Only zoom if there's actually a change
     if(delta_y != 0)
     {
@@ -821,16 +823,16 @@ namespace glfw
     }
 
     core.clear_framebuffers();
-    if (callback_pre_draw)
+    for (unsigned int i = 0; i<plugins.size(); ++i)
     {
-      if (callback_pre_draw(*this))
+      if (plugins[i]->pre_draw())
       {
         return;
       }
     }
-    for (unsigned int i = 0; i<plugins.size(); ++i)
+    if (callback_pre_draw)
     {
-      if (plugins[i]->pre_draw())
+      if (callback_pre_draw(*this))
       {
         return;
       }
@@ -839,18 +841,18 @@ namespace glfw
     {
       core.draw(data_list[i]);
     }
-    if (callback_post_draw)
+    for (unsigned int i = 0; i<plugins.size(); ++i)
     {
-      if (callback_post_draw(*this))
+      if (plugins[i]->post_draw())
       {
-        return;
+        break;
       }
     }
-    for (unsigned int i = 0; i<plugins.size(); ++i)
+    if (callback_post_draw)
     {
-      if (plugins[i]->post_draw())
+      if (callback_post_draw(*this))
       {
-        break;
+        return;
       }
     }
   }