* statusbar: show selected brushes/patches/entities counts, if anything is selected; total, if not

This commit is contained in:
Garux 2018-06-01 02:23:07 +03:00
parent 24c02facb2
commit c0b6f2169a
4 changed files with 56 additions and 2 deletions

View File

@ -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;

View File

@ -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<int>( g_si_globals.rotate );
//}
@ -3645,6 +3649,7 @@ void MainFrame_Construct(){
g_patchCount.setCountChangedCallback( FreeCaller<QE_brushCountChanged>() );
g_entityCount.setCountChangedCallback( FreeCaller<QE_brushCountChanged>() );
GlobalEntityCreator().setCounter( &g_entityCount );
GlobalSelectionSystem().addSelectionChangeCallback( FreeCaller1<const Selectable&, brushCountChanged>() );
GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;

View File

@ -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<QE_brushCountChange>() );
void QE_brushCountChanged(){
g_idle_scene_counts_update.queueDraw();
}
bool ConfirmModified( const char* title ){
if ( !Map_Modified( g_map ) ) {

View File

@ -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" );