X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fselectionlib.h;h=06a905c74a2440c071e4eaf2da00e79010e5e19f;hb=42856811f2b174e37a761bfcb9fbeb8c6af2f558;hp=b842616e1400179a5a259fe5269e3b754a828717;hpb=231225d6f97d0b926b2e896e5783cccfbc7c5619;p=xonotic%2Fnetradiant.git diff --git a/libs/selectionlib.h b/libs/selectionlib.h index b842616e..06a905c7 100644 --- a/libs/selectionlib.h +++ b/libs/selectionlib.h @@ -1,25 +1,25 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined (INCLUDED_SELECTIONLIB_H) +#if !defined ( INCLUDED_SELECTIONLIB_H ) #define INCLUDED_SELECTIONLIB_H #include "iselection.h" @@ -29,122 +29,104 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class SelectableBool : public Selectable { - bool m_selected; +bool m_selected; public: - SelectableBool() - : m_selected(false) - {} - - void setSelected(bool select = true) - { - m_selected = select; - } - bool isSelected() const - { - return m_selected; - } +SelectableBool() + : m_selected( false ) +{} + +void setSelected( bool select = true ){ + m_selected = select; +} +bool isSelected() const { + return m_selected; +} }; class ObservedSelectable : public Selectable { - SelectionChangeCallback m_onchanged; - bool m_selected; +SelectionChangeCallback m_onchanged; +bool m_selected; public: - ObservedSelectable(const SelectionChangeCallback& onchanged) : m_onchanged(onchanged), m_selected(false) - { - } - ObservedSelectable(const ObservedSelectable& other) : Selectable(other), m_onchanged(other.m_onchanged), m_selected(false) - { - setSelected(other.isSelected()); - } - ObservedSelectable& operator=(const ObservedSelectable& other) - { - setSelected(other.isSelected()); - return *this; - } - ~ObservedSelectable() - { - setSelected(false); - } - - void setSelected(bool select) - { - if(select ^ m_selected) - { - m_selected = select; - - m_onchanged(*this); - } - } - bool isSelected() const - { - return m_selected; - } +ObservedSelectable( const SelectionChangeCallback& onchanged ) : m_onchanged( onchanged ), m_selected( false ){ +} +ObservedSelectable( const ObservedSelectable& other ) : Selectable( other ), m_onchanged( other.m_onchanged ), m_selected( false ){ + setSelected( other.isSelected() ); +} +ObservedSelectable& operator=( const ObservedSelectable& other ){ + setSelected( other.isSelected() ); + return *this; +} +~ObservedSelectable(){ + setSelected( false ); +} + +void setSelected( bool select ){ + if ( select ^ m_selected ) { + m_selected = select; + + m_onchanged( *this ); + } +} +bool isSelected() const { + return m_selected; +} }; class SelectableInstance : public scene::Instance { - class TypeCasts - { - InstanceTypeCastTable m_casts; - public: - TypeCasts() - { - InstanceContainedCast::install(m_casts); - } - InstanceTypeCastTable& get() - { - return m_casts; - } - }; - - ObservedSelectable m_selectable; +class TypeCasts +{ +InstanceTypeCastTable m_casts; +public: +TypeCasts(){ + InstanceContainedCast::install( m_casts ); +} +InstanceTypeCastTable& get(){ + return m_casts; +} +}; + +ObservedSelectable m_selectable; public: - typedef LazyStatic StaticTypeCasts; - - SelectableInstance(const scene::Path& path, scene::Instance* parent, void* instance = 0, InstanceTypeCastTable& casts = StaticTypeCasts::instance().get()) : - Instance(path, parent, instance != 0 ? instance : this, casts), - m_selectable(SelectedChangedCaller(*this)) - { - } - - Selectable& get(NullType) - { - return m_selectable; - } - - Selectable& getSelectable() - { - return m_selectable; - } - const Selectable& getSelectable() const - { - return m_selectable; - } - - void selectedChanged(const Selectable& selectable) - { - GlobalSelectionSystem().getObserver(SelectionSystem::ePrimitive)(selectable); - GlobalSelectionSystem().onSelectedChanged(*this, selectable); - - Instance::selectedChanged(); - } - typedef MemberCaller1 SelectedChangedCaller; +typedef LazyStatic StaticTypeCasts; + +SelectableInstance( const scene::Path& path, scene::Instance* parent, void* instance = 0, InstanceTypeCastTable& casts = StaticTypeCasts::instance().get() ) : + Instance( path, parent, instance != 0 ? instance : this, casts ), + m_selectable( SelectedChangedCaller( *this ) ){ +} + +Selectable& get( NullType){ + return m_selectable; +} + +Selectable& getSelectable(){ + return m_selectable; +} +const Selectable& getSelectable() const { + return m_selectable; +} + +void selectedChanged( const Selectable& selectable ){ + GlobalSelectionSystem().getObserver ( SelectionSystem::ePrimitive )( selectable ); + GlobalSelectionSystem().onSelectedChanged( *this, selectable ); + + Instance::selectedChanged(); +} +typedef MemberCaller SelectedChangedCaller; }; template -inline bool range_check(Iterator start, Iterator finish, Iterator iter) -{ - for(;start != finish; ++start) - { - if(start == iter) - { - return true; - } - } - return false; +inline bool range_check( Iterator start, Iterator finish, Iterator iter ){ + for (; start != finish; ++start ) + { + if ( start == iter ) { + return true; + } + } + return false; } #include @@ -152,55 +134,45 @@ inline bool range_check(Iterator start, Iterator finish, Iterator iter) template class SelectionList { - typedef std::list List; - List m_selection; +typedef std::list List; +List m_selection; public: - typedef typename List::iterator iterator; - typedef typename List::const_iterator const_iterator; - - iterator begin() - { - return m_selection.begin(); - } - const_iterator begin() const - { - return m_selection.begin(); - } - iterator end() - { - return m_selection.end(); - } - const_iterator end() const - { - return m_selection.end(); - } - bool empty() const - { - return m_selection.empty(); - } - std::size_t size() const - { - return m_selection.size(); - } - Selected& back() - { - return *m_selection.back(); - } - Selected& back() const - { - return *m_selection.back(); - } - void append(Selected& selected) - { - m_selection.push_back(&selected); - } - void erase(Selected& selected) - { - typename List::reverse_iterator i = std::find(m_selection.rbegin(), m_selection.rend(), &selected); - ASSERT_MESSAGE(i != m_selection.rend(), "selection-tracking error"); - ASSERT_MESSAGE(range_check(m_selection.begin(), m_selection.end(), --i.base()), "selection-tracking error"); - m_selection.erase(--i.base()); - } +typedef typename List::iterator iterator; +typedef typename List::const_iterator const_iterator; + +iterator begin(){ + return m_selection.begin(); +} +const_iterator begin() const { + return m_selection.begin(); +} +iterator end(){ + return m_selection.end(); +} +const_iterator end() const { + return m_selection.end(); +} +bool empty() const { + return m_selection.empty(); +} +std::size_t size() const { + return m_selection.size(); +} +Selected& back(){ + return *m_selection.back(); +} +Selected& back() const { + return *m_selection.back(); +} +void append( Selected& selected ){ + m_selection.push_back( &selected ); +} +void erase( Selected& selected ){ + typename List::reverse_iterator i = std::find( m_selection.rbegin(), m_selection.rend(), &selected ); + ASSERT_MESSAGE( i != m_selection.rend(), "selection-tracking error" ); + ASSERT_MESSAGE( range_check( m_selection.begin(), m_selection.end(), --i.base() ), "selection-tracking error" ); + m_selection.erase( --i.base() ); +} };