shorten code

This commit is contained in:
Garux 2019-08-23 14:40:45 +03:00
parent da7c72547b
commit 4e82cdf2f4
7 changed files with 49 additions and 180 deletions

View File

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

View File

@ -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<MainFrame, XY_UpdateAllWindows>( *this ) );
AddGridChangeCallback( FreeCaller<XY_UpdateAllWindows>() );
g_defaultToolMode = DragMode;
g_defaultToolMode();

View File

@ -123,6 +123,13 @@ CamWnd* GetCamWnd(){
return m_pCamWnd;
}
template<typename Functor>
void forEachXYWnd( const Functor& functor ){
for( XYWnd* xywnd : { GetXYWnd(), GetXZWnd(), GetYZWnd() } )
if( xywnd )
functor( xywnd );
}
EViewStyle CurrentStyle(){
return m_nCurrentStyle;
}

View File

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

View File

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

View File

@ -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<VIEWTYPE>( ( 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<int, MSAAImport> 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<XY_Next>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
GlobalCommands_insert( "NextView", FreeCaller<XY_NextView>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_Delete ) );
GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_Insert ) );
GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KP_7 ) );

View File

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