Просмотр исходного кода

add GuiManager::sanity_check()

Cary Sandvig 25 лет назад
Родитель
Сommit
450d263f78
2 измененных файлов с 34 добавлено и 0 удалено
  1. 32 0
      panda/src/gui/guiManager.cxx
  2. 2 0
      panda/src/gui/guiManager.h

+ 32 - 0
panda/src/gui/guiManager.cxx

@@ -201,3 +201,35 @@ void GuiManager::recompute_priorities(void) {
   }
   _next_draw_order = p;
 }
+
+INLINE bool in_range(float x, float a, float b) {
+  return ((x >= a) && (x <= b));
+}
+
+INLINE bool overlap(GuiRegion* a, GuiRegion* b) {
+  LVector4f av = a->get_frame();
+  LVector4f bv = b->get_frame();
+
+  if (in_range(av[0], bv[0], bv[1]) ||
+      in_range(av[1], bv[0], bv[1]) ||
+      in_range(av[2], bv[2], bv[3]) ||
+      in_range(av[3], bv[2], bv[3]))
+    return true;
+  return false;
+}
+
+void GuiManager::sanity_check(void) const {
+  for (RegionSet::const_iterator i=_regions.begin(); i!=_regions.end(); ++i)
+    for (RegionSet::const_iterator j=_regions.begin(); j!=_regions.end(); ++j) {
+      if ((*i) == (*j))
+	continue;
+      if (overlap((*i), (*j)))
+	gui_cat->warning() << "GuiManager::sanity_check: overlapping regions '"
+			   << (*i)->get_name() << "' and '" << (*j)->get_name()
+			   << "'" << endl;
+      if ((*i)->get_name() == (*j)->get_name())
+	gui_cat->warning() << "GuiManager::sanity_check: regions with same "
+			   << "name '" << (*i)->get_name() << " 0x"
+			   << (void*)(*i) << " and 0x" << (void*)(*j) << endl;
+    }
+}

+ 2 - 0
panda/src/gui/guiManager.h

@@ -57,6 +57,8 @@ PUBLISHED:
   INLINE void set_next_draw_order(int);
   INLINE int get_start_draw_order(void) const;
   INLINE void set_start_draw_order(int);
+
+  void sanity_check(void) const;
 };
 
 #include "guiManager.I"