From c0b6f2169a8bec4c1c8c4d39da7ba701c0e145b0 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 1 Jun 2018 02:23:07 +0300 Subject: [PATCH] * statusbar: show selected brushes/patches/entities counts, if anything is selected; total, if not --- include/iselection.h | 1 + radiant/mainframe.cpp | 5 +++++ radiant/qe3.cpp | 15 +++++++++++++-- radiant/selection.cpp | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/include/iselection.h b/include/iselection.h index a2b00275..3f98c640 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -100,6 +100,7 @@ virtual EManipulatorMode ManipulatorMode() const = 0; virtual SelectionChangeCallback getObserver( EMode mode ) = 0; virtual std::size_t countSelected() const = 0; virtual std::size_t countSelectedComponents() const = 0; +virtual void countSelectedStuff( std::size_t& brushes, std::size_t& patches, std::size_t& entities ) const = 0; virtual void onSelectedChanged( scene::Instance& instance, const Selectable& selectable ) = 0; virtual void onComponentSelection( scene::Instance& instance, const Selectable& selectable ) = 0; virtual scene::Instance& ultimateSelected() const = 0; diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index ea127aa7..dc2dfaaf 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -3316,6 +3316,10 @@ void Sys_Status( const char* status ){ g_pParentWnd->SetStatusText( c_status_command, status ); } +void brushCountChanged( const Selectable& selectable ){ + QE_brushCountChanged(); +} + //int getRotateIncrement(){ // return static_cast( g_si_globals.rotate ); //} @@ -3645,6 +3649,7 @@ void MainFrame_Construct(){ g_patchCount.setCountChangedCallback( FreeCaller() ); g_entityCount.setCountChangedCallback( FreeCaller() ); GlobalEntityCreator().setCounter( &g_entityCount ); + GlobalSelectionSystem().addSelectionChangeCallback( FreeCaller1() ); GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated; GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed; diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 9c34b15d..633381e0 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -123,12 +123,23 @@ SimpleCounter g_brushCount; SimpleCounter g_patchCount; SimpleCounter g_entityCount; -void QE_brushCountChanged(){ +void QE_brushCountChange(){ char buffer[128]; - sprintf( buffer, "Brushes: %u Patches: %u Entities: %u", Unsigned( g_brushCount.get() ), Unsigned( g_patchCount.get() ), Unsigned( g_entityCount.get() ) ); + if( GlobalSelectionSystem().countSelected() == 0 ) + sprintf( buffer, "Brushes: %u Patches: %u Entities: %u", Unsigned( g_brushCount.get() ), Unsigned( g_patchCount.get() ), Unsigned( g_entityCount.get() ) ); + else{ + std::size_t brushes, patches, entities; + GlobalSelectionSystem().countSelectedStuff( brushes, patches, entities ); + sprintf( buffer, "Brushes: %u Patches: %u Entities: %u", Unsigned( brushes ), Unsigned( patches ), Unsigned( entities ) ); + } g_pParentWnd->SetStatusText( c_status_brushcount, buffer ); } +IdleDraw g_idle_scene_counts_update = IdleDraw( FreeCaller() ); +void QE_brushCountChanged(){ + g_idle_scene_counts_update.queueDraw(); +} + bool ConfirmModified( const char* title ){ if ( !Map_Modified( g_map ) ) { diff --git a/radiant/selection.cpp b/radiant/selection.cpp index 597dc9aa..23e55bae 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -2996,6 +2996,37 @@ std::size_t m_count; SelectionChangeCallback m_onchanged; }; +class SelectedStuffCounter +{ +public: + std::size_t m_brushcount; + std::size_t m_patchcount; + std::size_t m_entitycount; + SelectedStuffCounter() : m_brushcount( 0 ), m_patchcount( 0 ), m_entitycount( 0 ){ + } + void increment( scene::Node& node ) { + if( Node_isBrush( node ) ) + ++m_brushcount; + else if( Node_isPatch( node ) ) + ++m_patchcount; + else if( Node_isEntity( node ) ) + ++m_entitycount; + } + void decrement( scene::Node& node ) { + if( Node_isBrush( node ) ) + --m_brushcount; + else if( Node_isPatch( node ) ) + --m_patchcount; + else if( Node_isEntity( node ) ) + --m_entitycount; + } + void get( std::size_t& brushes, std::size_t& patches, std::size_t& entities ) const { + brushes = m_brushcount; + patches = m_patchcount; + entities = m_entitycount; + } +}; + inline void ConstructSelectionTest( View& view, const rect_t selection_box ){ view.EnableScissor( selection_box.min[0], selection_box.max[0], selection_box.min[1], selection_box.max[1] ); } @@ -4156,6 +4187,7 @@ EComponentMode m_componentmode; SelectionCounter m_count_primitive; SelectionCounter m_count_component; +SelectedStuffCounter m_count_stuff; TranslateManipulator m_translate_manipulator; RotateManipulator m_rotate_manipulator; @@ -4286,13 +4318,18 @@ std::size_t countSelected() const { std::size_t countSelectedComponents() const { return m_count_component.size(); } +void countSelectedStuff( std::size_t& brushes, std::size_t& patches, std::size_t& entities ) const { + m_count_stuff.get( brushes, patches, entities ); +} void onSelectedChanged( scene::Instance& instance, const Selectable& selectable ){ if ( selectable.isSelected() ) { m_selection.append( instance ); + m_count_stuff.increment( instance.path().top() ); } else { m_selection.erase( instance ); + m_count_stuff.decrement( instance.path().top() ); } ASSERT_MESSAGE( m_selection.size() == m_count_primitive.size(), "selection-tracking error" );