From 09c0da616cce898ba8ac2aa744f14c561ff3b36a Mon Sep 17 00:00:00 2001 From: neumond Date: Mon, 24 Mar 2014 06:57:46 +0400 Subject: [PATCH] Improved mousewheel zoom-in --- radiant/camwindow.cpp | 2 +- radiant/camwindow.h | 2 +- radiant/glwindow.cpp | 6 +++--- radiant/glwindow.h | 2 +- radiant/texwindow.cpp | 2 +- radiant/texwindow.h | 2 +- radiant/xywindow.cpp | 10 +++++++++- radiant/xywindow.h | 2 +- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 4e3b8c0b..8a952be0 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -168,7 +168,7 @@ void CamWnd::OnMouseMove( guint32 flags, int pointx, int pointy ){ update_xor_rectangle( m_XORRectangle ); } -void CamWnd::OnMouseWheel( bool bUp ){ +void CamWnd::OnMouseWheel( bool bUp, int pointx, int pointy ){ if ( bUp ) { VectorMA( m_Camera.origin, g_PrefsDlg.m_nMoveSpeed, m_Camera.forward, m_Camera.origin ); } diff --git a/radiant/camwindow.h b/radiant/camwindow.h index 0978e683..674df16f 100644 --- a/radiant/camwindow.h +++ b/radiant/camwindow.h @@ -148,7 +148,7 @@ void OnLButtonUp( guint32 flags, int pointx, int pointy ); void OnRButtonUp( guint32 flags, int pointx, int pointy ); void OnMButtonUp( guint32 flags, int pointx, int pointy ); void OnMouseMove( guint32 flags, int pointx, int pointy ); -void OnMouseWheel( bool bUp ); +void OnMouseWheel( bool bUp, int pointx, int pointy ); void OnSize( int cx, int cy ); protected: diff --git a/radiant/glwindow.cpp b/radiant/glwindow.cpp index 92ae7c8b..92679836 100644 --- a/radiant/glwindow.cpp +++ b/radiant/glwindow.cpp @@ -79,8 +79,8 @@ static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer dat case 2: flags |= MK_MBUTTON; break; case 3: flags |= MK_RBUTTON; break; #if !GTK_CHECK_VERSION( 1,3,0 ) - case 4: wnd->OnMouseWheel( true ); break; - case 5: wnd->OnMouseWheel( false ); break; + case 4: wnd->OnMouseWheel( true, (int)event->x, (int)event->y ); break; + case 5: wnd->OnMouseWheel( false, (int)event->x, (int)event->y ); break; #endif } @@ -177,7 +177,7 @@ static gint scroll_event( GtkWidget *widget, GdkEventScroll *event, gpointer data ){ GLWindow *wnd = (GLWindow*)data; - wnd->OnMouseWheel( ( event->direction == GDK_SCROLL_UP ) ? true : false ); + wnd->OnMouseWheel( ( event->direction == GDK_SCROLL_UP ) ? true : false, (int)event->x, (int)event->y ); return TRUE; } #endif diff --git a/radiant/glwindow.h b/radiant/glwindow.h index d5f6c732..f0903534 100644 --- a/radiant/glwindow.h +++ b/radiant/glwindow.h @@ -58,7 +58,7 @@ public: virtual void OnSize( int cx, int cy ) { } virtual void OnTimer() { } - virtual void OnMouseWheel( bool bUp ) { } + virtual void OnMouseWheel( bool bUp, int pointx, int pointy ) { } void RedrawWindow() { gtk_widget_queue_draw( m_pWidget ); } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index db284edf..4223388b 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -1784,7 +1784,7 @@ void TexWnd::FocusEdit() { } } -void TexWnd::OnMouseWheel( bool bUp ){ +void TexWnd::OnMouseWheel( bool bUp, int pointx, int pointy ){ if ( bUp ) { if ( g_qeglobals.d_texturewin.originy < 0 ) { g_qeglobals.d_texturewin.originy += g_PrefsDlg.m_nWheelInc; diff --git a/radiant/texwindow.h b/radiant/texwindow.h index da794345..ae01183a 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -50,7 +50,7 @@ void OnMButtonUp( guint32 flags, int pointx, int pointy ); void OnMouseMove( guint32 flags, int pointx, int pointy ); void OnSize( int cx, int cy ); -void OnMouseWheel( bool bUp ); +void OnMouseWheel( bool bUp, int pointx, int pointy ); public: void OnVScroll(); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 560eb8fe..aaf19a98 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1156,9 +1156,17 @@ void XYWnd::OnMouseMove( guint32 nFlags, int pointx, int pointy ){ update_xor_rectangle_xy( m_XORRectangle ); } -void XYWnd::OnMouseWheel( bool bUp ){ +void XYWnd::OnMouseWheel( bool bUp, int pointx, int pointy ){ if ( bUp ) { + // improved zoom-in + // frame coverges to part of window where the cursor currently resides + float old_scale = m_fScale; g_pParentWnd->OnViewZoomin(); + float scale_diff = 1.0 / old_scale - 1.0 / m_fScale; + int nDim1 = ( m_nViewType == YZ ) ? 1 : 0; + int nDim2 = ( m_nViewType == XY ) ? 1 : 2; + m_vOrigin[nDim1] += scale_diff * (pointx - 0.5 * m_nWidth); + m_vOrigin[nDim2] -= scale_diff * (pointy - 0.5 * m_nHeight); } else{ g_pParentWnd->OnViewZoomout(); diff --git a/radiant/xywindow.h b/radiant/xywindow.h index 31bfbeda..5f903d57 100644 --- a/radiant/xywindow.h +++ b/radiant/xywindow.h @@ -191,7 +191,7 @@ void OnLButtonUp( guint32 flags, int pointx, int pointy ); void OnRButtonUp( guint32 flags, int pointx, int pointy ); void OnMButtonUp( guint32 flags, int pointx, int pointy ); void OnMouseMove( guint32 nFlags, int pointx, int pointy ); -void OnMouseWheel( bool bUp ); +void OnMouseWheel( bool bUp, int pointx, int pointy ); void OnSize( int cx, int cy ); void OnTimer();