00001 /* 00002 Copyright (C) 2001-2006, William Joseph. 00003 All Rights Reserved. 00004 00005 This file is part of GtkRadiant. 00006 00007 GtkRadiant is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 GtkRadiant is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GtkRadiant; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #if !defined(INCLUDED_FILTERS_H) 00023 #define INCLUDED_FILTERS_H 00024 00025 #include "ifilter.h" 00026 00027 #include "generic/callback.h" 00028 #include "scenelib.h" 00029 00030 class Entity; 00031 00032 class EntityFilter 00033 { 00034 public: 00035 virtual ~EntityFilter () 00036 { 00037 } 00038 virtual bool filter (const Entity& entity) const = 0; 00039 }; 00040 00041 bool entity_filtered (Entity& entity); 00042 void add_entity_filter (EntityFilter& filter, int mask, bool invert = false); 00043 00044 class ClassnameFilter: public Filterable 00045 { 00046 scene::Node& m_node; 00047 public: 00048 Entity& m_entity; 00049 00050 ClassnameFilter (Entity& entity, scene::Node& node) : 00051 m_node(node), m_entity(entity) 00052 { 00053 } 00054 ~ClassnameFilter () 00055 { 00056 } 00057 00058 void instanceAttach () 00059 { 00060 GlobalFilterSystem().registerFilterable(*this); 00061 } 00062 void instanceDetach () 00063 { 00064 GlobalFilterSystem().unregisterFilterable(*this); 00065 } 00066 00067 void updateFiltered () 00068 { 00069 if (entity_filtered(m_entity)) { 00070 m_node.enable(scene::Node::eFiltered); 00071 } else { 00072 m_node.disable(scene::Node::eFiltered); 00073 } 00074 } 00075 00076 void classnameChanged (const std::string& value) 00077 { 00078 updateFiltered(); 00079 } 00080 typedef MemberCaller1<ClassnameFilter, const std::string&, &ClassnameFilter::classnameChanged> ClassnameChangedCaller; 00081 }; 00082 00083 #endif