filters.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (C) 2001-2006, William Joseph.
  3. All Rights Reserved.
  4. This file is part of GtkRadiant.
  5. GtkRadiant is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. GtkRadiant is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GtkRadiant; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #include "filters.h"
  18. #include "ifilter.h"
  19. #include <list>
  20. class EntityFilterWrapper : public Filter
  21. {
  22. bool m_active;
  23. bool m_invert;
  24. EntityFilter& m_filter;
  25. public:
  26. EntityFilterWrapper(EntityFilter& filter, bool invert) : m_invert(invert), m_filter(filter)
  27. {
  28. }
  29. void setActive(bool active)
  30. {
  31. m_active = active;
  32. }
  33. bool active()
  34. {
  35. return m_active;
  36. }
  37. bool filter(const Entity& entity)
  38. {
  39. return m_invert ^ m_filter.filter(entity);
  40. }
  41. };
  42. typedef std::list<EntityFilterWrapper> EntityFilters;
  43. EntityFilters g_entityFilters;
  44. void add_entity_filter(EntityFilter& filter, int mask, bool invert)
  45. {
  46. g_entityFilters.push_back(EntityFilterWrapper(filter, invert));
  47. GlobalFilterSystem().addFilter(g_entityFilters.back(), mask);
  48. }
  49. bool entity_filtered(Entity& entity)
  50. {
  51. for(EntityFilters::iterator i = g_entityFilters.begin(); i != g_entityFilters.end(); ++i)
  52. {
  53. if((*i).active() && (*i).filter(entity))
  54. {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }