diff --git a/radiant/clippertool.cpp b/radiant/clippertool.cpp index a23cdf88..6bdb917f 100644 --- a/radiant/clippertool.cpp +++ b/radiant/clippertool.cpp @@ -97,13 +97,9 @@ void Clipper_modeChanged( bool isClipper ){ GdkCursor* cursor = isClipper? g_clipper_cursor : 0; if( g_pParentWnd ){ - XYWnd* xywnd; - if( ( xywnd = g_pParentWnd->GetXYWnd() ) ) - gdk_window_set_cursor( xywnd->GetWidget()->window, cursor ); - if( ( xywnd = g_pParentWnd->GetXZWnd() ) ) - gdk_window_set_cursor( xywnd->GetWidget()->window, cursor ); - if( ( xywnd = g_pParentWnd->GetYZWnd() ) ) + g_pParentWnd->forEachXYWnd( [&cursor]( XYWnd* xywnd ){ gdk_window_set_cursor( xywnd->GetWidget()->window, cursor ); + } ); if( g_pParentWnd->GetCamWnd() ) if( !isClipper || gdk_pointer_is_grabbed() == FALSE ) /* prevent cursor change `GDK_BLANK_CURSOR->g_clipper_cursor` during freelook */ gdk_window_set_cursor( CamWnd_getWidget( *g_pParentWnd->GetCamWnd() )->window, cursor ); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 38f7c847..76c571cf 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -728,14 +728,7 @@ void Paste(){ void TranslateToCamera(){ CamWnd& camwnd = *g_pParentWnd->GetCamWnd(); - // Work out the delta - Vector3 mid; - Select_GetMid( mid ); - //Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid ); - Vector3 delta = vector3_snapped( vector3_subtracted( Camera_getOrigin( camwnd ), mid ), GetSnapGridSize() ); - - // Move to camera - GlobalSelectionSystem().translateSelected( delta ); + GlobalSelectionSystem().translateSelected( vector3_snapped( Camera_getOrigin( camwnd ) - GlobalSelectionSystem().getBoundsSelected().origin, GetSnapGridSize() ) ); } void PasteToCamera(){ @@ -1945,33 +1938,11 @@ void GlobalCamera_UpdateWindow(){ } } -void XY_UpdateWindow( MainFrame& mainframe ){ - if ( mainframe.GetXYWnd() != 0 ) { - XYWnd_Update( *mainframe.GetXYWnd() ); - } -} - -void XZ_UpdateWindow( MainFrame& mainframe ){ - if ( mainframe.GetXZWnd() != 0 ) { - XYWnd_Update( *mainframe.GetXZWnd() ); - } -} - -void YZ_UpdateWindow( MainFrame& mainframe ){ - if ( mainframe.GetYZWnd() != 0 ) { - XYWnd_Update( *mainframe.GetYZWnd() ); - } -} - -void XY_UpdateAllWindows( MainFrame& mainframe ){ - XY_UpdateWindow( mainframe ); - XZ_UpdateWindow( mainframe ); - YZ_UpdateWindow( mainframe ); -} - void XY_UpdateAllWindows(){ if ( g_pParentWnd != 0 ) { - XY_UpdateAllWindows( *g_pParentWnd ); + g_pParentWnd->forEachXYWnd( []( XYWnd* xywnd ){ + XYWnd_Update( *xywnd ); + } ); } } @@ -3321,7 +3292,7 @@ void MainFrame::Create(){ SetActiveXY( m_pXYWnd ); AddGridChangeCallback( SetGridStatusCaller( *this ) ); - AddGridChangeCallback( ReferenceCaller( *this ) ); + AddGridChangeCallback( FreeCaller() ); g_defaultToolMode = DragMode; g_defaultToolMode(); diff --git a/radiant/mainframe.h b/radiant/mainframe.h index 2a175006..a2d593b5 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -123,6 +123,13 @@ CamWnd* GetCamWnd(){ return m_pCamWnd; } +template +void forEachXYWnd( const Functor& functor ){ + for( XYWnd* xywnd : { GetXYWnd(), GetXZWnd(), GetYZWnd() } ) + if( xywnd ) + functor( xywnd ); +} + EViewStyle CurrentStyle(){ return m_nCurrentStyle; } diff --git a/radiant/select.cpp b/radiant/select.cpp index de56a251..19f7d61b 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -539,10 +539,6 @@ void Select_GetBounds( Vector3& mins, Vector3& maxs ){ mins = vector3_subtracted( bounds.origin, bounds.extents ); } -void Select_GetMid( Vector3& mid ){ - mid = vector3_snapped( GlobalSelectionSystem().getBoundsSelected().origin ); -} - void Select_FlipAxis( int axis ){ Vector3 flip( 1, 1, 1 ); diff --git a/radiant/select.h b/radiant/select.h index 510390c6..0542446b 100644 --- a/radiant/select.h +++ b/radiant/select.h @@ -25,7 +25,6 @@ #include "math/vector.h" void Select_GetBounds( Vector3& mins, Vector3& maxs ); -void Select_GetMid( Vector3& mid ); void Select_Delete(); void Select_Invert(); @@ -34,13 +33,6 @@ void Select_Touching(); void Scene_ExpandSelectionToPrimitives(); void Scene_ExpandSelectionToEntities(); -//void Selection_Flipx(); -//void Selection_Flipy(); -//void Selection_Flipz(); -//void Selection_Rotatex(); -//void Selection_Rotatey(); -//void Selection_Rotatez(); - void Selection_MoveDown(); void Selection_MoveUp(); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 46821754..64a5f25a 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -292,7 +292,7 @@ void XYWnd::ZoomInWithMouse( int pointx, int pointy ){ } } -void XYWnd::FocusOnBounds( AABB& bounds ){ +void XYWnd::FocusOnBounds( const AABB& bounds ){ SetOrigin( bounds.origin ); int nDim1 = ( m_viewType == YZ ) ? 1 : 0; int nDim2 = ( m_viewType == XY ) ? 1 : 2; @@ -2393,150 +2393,63 @@ void XYWnd::OnEntityCreate( const char* item ){ -void GetCenterPosition( Vector3& position ){ - if ( GlobalSelectionSystem().countSelected() != 0 ) { - Select_GetMid( position ); - } - else - { - position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() ); - } +inline AABB GetCenterBbox(){ + return ( GlobalSelectionSystem().countSelected() != 0 )? + GlobalSelectionSystem().getBoundsSelected() : + AABB( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Vector3( 128.f, 128.f, 128.f ) ); } void XYWnd_Centralize( XYWnd* xywnd ){ - Vector3 position; - GetCenterPosition( position ); - xywnd->PositionView( position ); -} - -void XY_Split_Centralize(){ - Vector3 position; - GetCenterPosition( position ); - if ( g_pParentWnd->GetXYWnd() ) { - g_pParentWnd->GetXYWnd()->PositionView( position ); - } - if ( g_pParentWnd->GetXZWnd() ) { - g_pParentWnd->GetXZWnd()->PositionView( position ); - } - if ( g_pParentWnd->GetYZWnd() ) { - g_pParentWnd->GetYZWnd()->PositionView( position ); - } + xywnd->PositionView( GetCenterBbox().origin ); } void XY_Centralize(){ - if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) { - // centralize all - XY_Split_Centralize(); - return; - } - - XYWnd* xywnd = g_pParentWnd->GetXYWnd(); - XYWnd_Centralize( xywnd ); -} - - - -void GetSelectionBbox( AABB& bounds ){ - if ( GlobalSelectionSystem().countSelected() != 0 ) { - bounds = GlobalSelectionSystem().getBoundsSelected(); - } - else - { - bounds = AABB( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Vector3( 128.f, 128.f, 128.f ) ); - } -} - -void XYWnd_Focus( XYWnd* xywnd ){ - AABB bounds; - GetSelectionBbox( bounds ); - xywnd->FocusOnBounds( bounds ); -} - -void XY_Split_Focus(){ - AABB bounds; - GetSelectionBbox( bounds ); - if ( g_pParentWnd->GetXYWnd() ) { - g_pParentWnd->GetXYWnd()->FocusOnBounds( bounds ); - } - if ( g_pParentWnd->GetXZWnd() ) { - g_pParentWnd->GetXZWnd()->FocusOnBounds( bounds ); - } - if ( g_pParentWnd->GetYZWnd() ) { - g_pParentWnd->GetYZWnd()->FocusOnBounds( bounds ); - } + const Vector3 position( GetCenterBbox().origin ); + g_pParentWnd->forEachXYWnd( [&position]( XYWnd* xywnd ){ + xywnd->PositionView( position ); + } ); } void XY_Focus(){ - if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) { - // focus all - XY_Split_Focus(); - return; - } - - XYWnd* xywnd = g_pParentWnd->GetXYWnd(); - XYWnd_Focus( xywnd ); + const AABB bounds( GetCenterBbox() ); + g_pParentWnd->forEachXYWnd( [&bounds]( XYWnd* xywnd ){ + xywnd->FocusOnBounds( bounds ); + } ); } -void XY_TopFrontSide( VIEWTYPE viewtype ){ - if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { - // cannot do this in a split window - // do something else that the user may want here - XY_Split_Centralize(); - return; +void XY_SetViewType( VIEWTYPE viewtype ){ + if ( g_pParentWnd->CurrentStyle() != MainFrame::eSplit ) { // do not want this in a split window + XYWnd* xywnd = g_pParentWnd->ActiveXY(); + xywnd->SetViewType( viewtype ); + XYWnd_Centralize( xywnd ); + } + else{ + XY_Centralize(); // do something else that the user may want here } - XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd(); - xywnd->SetViewType( viewtype ); - XYWnd_Centralize( xywnd ); } void XY_Top(){ - XY_TopFrontSide( XY ); + XY_SetViewType( XY ); } void XY_Front(){ - XY_TopFrontSide( XZ ); + XY_SetViewType( XZ ); } void XY_Side(){ - XY_TopFrontSide( YZ ); + XY_SetViewType( YZ ); } -void XY_NextView( XYWnd* xywnd ){ - if ( xywnd->GetViewType() == XY ) { - xywnd->SetViewType( XZ ); - } - else if ( xywnd->GetViewType() == XZ ) { - xywnd->SetViewType( YZ ); - } - else{ - xywnd->SetViewType( XY ); - } - XYWnd_Centralize( xywnd ); -} - -void XY_Next(){ - if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { - // cannot do this in a split window - // do something else that the user may want here - XY_Split_Centralize(); - return; - } - XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd(); - XY_NextView( xywnd ); +void XY_NextView(){ + XY_SetViewType( static_cast( ( g_pParentWnd->ActiveXY()->GetViewType() + 2 ) % 3 ) ); } void XY_Zoom100(){ - if ( g_pParentWnd->GetXYWnd() ) { - g_pParentWnd->GetXYWnd()->SetScale( 1 ); - } - if ( g_pParentWnd->GetXZWnd() ) { - g_pParentWnd->GetXZWnd()->SetScale( 1 ); - } - if ( g_pParentWnd->GetYZWnd() ) { - g_pParentWnd->GetYZWnd()->SetScale( 1 ); - } + g_pParentWnd->forEachXYWnd( []( XYWnd* xywnd ){ + xywnd->SetScale( 1 ); + } ); } void XY_ZoomIn(){ @@ -2737,15 +2650,9 @@ void ToggleShowGrid(){ void MSAAImport( int value ){ g_xywindow_globals_private.m_MSAA = value ? 1 << value : value; - if ( g_pParentWnd->GetXYWnd() ) { - g_pParentWnd->GetXYWnd()->fbo_get()->reset( g_pParentWnd->GetXYWnd()->Width(), g_pParentWnd->GetXYWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); - } - if ( g_pParentWnd->GetXZWnd() ) { - g_pParentWnd->GetXZWnd()->fbo_get()->reset( g_pParentWnd->GetXZWnd()->Width(), g_pParentWnd->GetXZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); - } - if ( g_pParentWnd->GetYZWnd() ) { - g_pParentWnd->GetYZWnd()->fbo_get()->reset( g_pParentWnd->GetYZWnd()->Width(), g_pParentWnd->GetYZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); - } + g_pParentWnd->forEachXYWnd( []( XYWnd* xywnd ){ + xywnd->fbo_get()->reset( xywnd->Width(), xywnd->Height(), g_xywindow_globals_private.m_MSAA, false ); + } ); } typedef FreeCaller1 MSAAImportCaller; @@ -2821,7 +2728,7 @@ void XYWindow_Construct(){ GlobalToggles_insert( "ToggleView", ToggleShown::ToggleCaller( g_xy_top_shown ), ToggleItem::AddCallbackCaller( g_xy_top_shown.m_item ) ); GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) ); GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) ); - GlobalCommands_insert( "NextView", FreeCaller(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "NextView", FreeCaller(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); GlobalCommands_insert( "ZoomIn", FreeCaller(), Accelerator( GDK_Delete ) ); GlobalCommands_insert( "ZoomOut", FreeCaller(), Accelerator( GDK_Insert ) ); GlobalCommands_insert( "ViewTop", FreeCaller(), Accelerator( GDK_KP_7 ) ); diff --git a/radiant/xywindow.h b/radiant/xywindow.h index 74a33705..21a3211f 100644 --- a/radiant/xywindow.h +++ b/radiant/xywindow.h @@ -155,7 +155,7 @@ guint m_zoom_focusOut; void ZoomIn(); void ZoomOut(); void ZoomInWithMouse( int pointx, int pointy ); -void FocusOnBounds( AABB& bounds ); +void FocusOnBounds( const AABB& bounds ); void SetActive( bool b ){ m_bActive = b;