X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fxywindow.cpp;h=5e67ecf2813394ebc4c881e16c647b3636fcc633;hb=0ae4329330f964c0e5af3742e365d71bb7d607fd;hp=237f44af26637db03be1633c6747e3a6c70d4cc6;hpb=e47e3afa806ffd805f91734dcd3cfcd68ad8d7b4;p=xonotic%2Fnetradiant.git diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 237f44af..5e67ecf2 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -501,17 +501,17 @@ void XYWnd::SetScale( float f ){ XYWnd_Update( *this ); } -void XYWnd_ZoomIn( XYWnd* xy ){ +void XYWnd::ZoomIn(){ float max_scale = 64; - float scale = xy->Scale() * 5.0f / 4.0f; + float scale = Scale() * 5.0f / 4.0f; if ( scale > max_scale ) { - if ( xy->Scale() != max_scale ) { - xy->SetScale( max_scale ); + if ( Scale() != max_scale ) { + SetScale( max_scale ); } } else { - xy->SetScale( scale ); + SetScale( scale ); } } @@ -519,17 +519,31 @@ void XYWnd_ZoomIn( XYWnd* xy ){ // NOTE: the zoom out factor is 4/5, we could think about customizing it // we don't go below a zoom factor corresponding to 10% of the max world size // (this has to be computed against the window size) -void XYWnd_ZoomOut( XYWnd* xy ){ - float min_scale = MIN( xy->Width(),xy->Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) ); - float scale = xy->Scale() * 4.0f / 5.0f; +void XYWnd::ZoomOut(){ + float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) ); + float scale = Scale() * 4.0f / 5.0f; if ( scale < min_scale ) { - if ( xy->Scale() != min_scale ) { - xy->SetScale( min_scale ); + if ( Scale() != min_scale ) { + SetScale( min_scale ); } } else { - xy->SetScale( scale ); + SetScale( scale ); + } +} + +void XYWnd::ZoomInWithMouse( int pointx, int pointy ){ + float old_scale = Scale(); + ZoomIn(); + if ( g_xywindow_globals.m_bImprovedWheelZoom ) { + float scale_diff = 1.0 / old_scale - 1.0 / Scale(); + int nDim1 = ( m_viewType == YZ ) ? 1 : 0; + int nDim2 = ( m_viewType == XY ) ? 1 : 2; + Vector3 origin = GetOrigin(); + origin[nDim1] += scale_diff * (pointx - 0.5 * Width()); + origin[nDim2] -= scale_diff * (pointy - 0.5 * Height()); + SetOrigin( origin ); } } @@ -767,10 +781,10 @@ void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){ gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){ if ( event->direction == GDK_SCROLL_UP ) { - XYWnd_ZoomIn( xywnd ); + xywnd->ZoomInWithMouse( (int)event->x, (int)event->y ); } else if ( event->direction == GDK_SCROLL_DOWN ) { - XYWnd_ZoomOut( xywnd ); + xywnd->ZoomOut(); } return FALSE; } @@ -1211,16 +1225,15 @@ int g_dragZoom = 0; void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){ if ( y != 0 ) { g_dragZoom += y; - while ( abs( g_dragZoom ) > 8 ) { if ( g_dragZoom > 0 ) { - XYWnd_ZoomOut( reinterpret_cast( data ) ); + reinterpret_cast( data )->ZoomOut(); g_dragZoom -= 8; } else { - XYWnd_ZoomIn( reinterpret_cast( data ) ); + reinterpret_cast( data )->ZoomIn(); g_dragZoom += 8; } } @@ -2530,14 +2543,14 @@ void XY_Zoom100(){ } void XY_ZoomIn(){ - XYWnd_ZoomIn( g_pParentWnd->ActiveXY() ); + g_pParentWnd->ActiveXY()->ZoomIn(); } // NOTE: the zoom out factor is 4/5, we could think about customizing it // we don't go below a zoom factor corresponding to 10% of the max world size // (this has to be computed against the window size) void XY_ZoomOut(){ - XYWnd_ZoomOut( g_pParentWnd->ActiveXY() ); + g_pParentWnd->ActiveXY()->ZoomOut(); } @@ -2777,6 +2790,7 @@ void XYWindow_Construct(){ GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) ); GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) ); + GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) ); GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) ); GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) ); GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );