mouse_zoom_handler.cpp
来自「ncbi源码」· C++ 代码 · 共 691 行 · 第 1/2 页
CPP
691 行
return 0;}int CMouseZoomHandler::x_OnMouseDrag(CGUIEvent& event){ switch(m_State) { case eScale: { int d_y = Fl::event_y() - m_MouseStartY; x_OnChangeScale(d_y); }; break; case eZoomRect: { x_OnChangeZoomRectPan(Fl::event_x(), Fl::event_y()); }; break; case ePan: { x_OnChangePan(); x_OnSelectCursor(); }; break; default: break; } return 1; // always handle drags}void CMouseZoomHandler::x_OnChangePan(){ m_CurrPosX = Fl::event_x(); m_CurrPosY = Fl::event_y(); int y1 = m_pHost->MZHH_GetVPPosByY(m_MouseStartY); int y2 = m_pHost->MZHH_GetVPPosByY(m_CurrPosY); TModelUnit m_x1 = m_pPane->UnProjectX(m_MouseStartX); TModelUnit m_y1 = m_pPane->UnProjectY(y1); TModelUnit m_x2 = m_pPane->UnProjectX(m_CurrPosX); TModelUnit m_y2 = m_pPane->UnProjectY(y2); m_pHost->MZHH_Scroll(m_x1 - m_x2, m_y1 - m_y2); m_pHost->MZHH_Redraw(); m_MouseStartX = m_CurrPosX; m_MouseStartY = m_CurrPosY;}int CMouseZoomHandler::x_OnMouseRelease(CGUIEvent& event){ switch(m_State) { case eScale: { int d_y = Fl::event_y() - m_MouseStartY; x_OnChangeScale(d_y); x_OnEndScale(eReadyScale); x_OnSelectCursor(); return 1; }; break; case eZoomRect: { x_OnChangeZoomRectPan(Fl::event_x(), Fl::event_y()); x_OnEndZoomRect(eReadyZoomRect); x_OnSelectCursor(); return 1; }; break; case ePan: { x_OnChangeZoomRectPan(Fl::event_x(), Fl::event_y()); x_OnEndPan(eReadyPan); x_OnSelectCursor(); return 1; }; break; default: break; } return 0;}int CMouseZoomHandler::x_OnMouseMove(void){ if(m_State != eIdle) { x_OnSelectCursor(); return 1; } else return 0;}static int kWheelRatio = 10;int CMouseZoomHandler::x_OnMouseWheel(CGUIEvent& event){ if(event.GetGUIState() == CGUIEvent::eZoomState) { switch(m_State) { case eIdle: x_SwitchToReadyState(eReadyScale, Fl::event_x(), Fl::event_y()); // continue case eReadyScale: { m_WheelTotalShift = 0; x_SwithToActiveState(eScale, Fl::event_x(), Fl::event_y()); }; // continue case eScale: { m_WheelTotalShift += Fl::event_dy() * kWheelRatio; x_OnChangeScale(m_WheelTotalShift); // updating shift after clipping with Min and Max norm values m_WheelTotalShift = (int) ((m_StartNorm - m_CurrNorm) * m_PixPerNorm); }; break; default: _ASSERT(false); break; } x_OnSelectCursor(); return 1; } else return 0;}int CMouseZoomHandler::x_OnKeyDown(CGUIEvent& event){ if(m_State == eIdle) { EState ready_st = eIdle; switch(event.GetGUIState()) { case CGUIEvent::eZoomState: ready_st = eReadyScale; break; case CGUIEvent::eZoomRectState: ready_st = eReadyZoomRect; break; case CGUIEvent::ePanState: ready_st = eReadyPan; break; default: break; } if(ready_st != eIdle) { x_SwitchToReadyState(ready_st, Fl::event_x(), Fl::event_y()); x_OnSelectCursor(); } } return (m_State == eIdle) ? 0 : 1; }int CMouseZoomHandler::x_OnKeyUp(CGUIEvent& event){ CGUIEvent::EGUIState state = event.GetGUIState(); if(state != CGUIEvent::eZoomState && state != CGUIEvent::eZoomRectState) { switch(m_State) { case eIdle: break; case eReadyScale: case eReadyZoomRect: case eReadyPan: case eZoomRect: case ePan: { m_pHost->MZHH_Redraw(); m_State = eIdle; x_OnSelectCursor(); }; break; case eScale: { x_OnEndScale(eIdle); m_State = eIdle; x_OnSelectCursor(); }; break; default: break; }; } return (m_State == eIdle) ? 0 : 1; }/////////////////////////////////////////////////////////////////////////////////// Signal handlersvoid CMouseZoomHandler::x_SwitchToReadyState(EState new_state, int pos_x, int pos_y){ _ASSERT(m_pHost); if(m_State != new_state) { m_State = new_state; m_CurrPosX = m_MarkerPosX = pos_x; m_CurrPosY = m_MarkerPosY = pos_y; if(m_State == eReadyScale) { m_CurrNorm = m_StartNorm = x_ScaleToNorm(m_pHost->MZHH_GetScale(IMouseZoomHandlerHost::eCurrent)); m_MinNorm = x_ScaleToNorm(m_pHost->MZHH_GetScale(IMouseZoomHandlerHost::eMin)); m_MaxNorm = x_ScaleToNorm(m_pHost->MZHH_GetScale(IMouseZoomHandlerHost::eMax)); } m_pHost->MZHH_Redraw(); }}void CMouseZoomHandler::x_SwithToActiveState(EState state, int pos_x, int pos_y){ _ASSERT(m_pHost); m_State = state; m_MouseStartX = pos_x; m_MouseStartY = pos_y; m_ptStart = m_pPane->UnProject(m_MouseStartX, m_pHost->MZHH_GetVPPosByY(m_MouseStartY));}/// d_y is the absolute shift in pixels from the position where m_StartNorm have/// been initializedvoid CMouseZoomHandler::x_OnChangeScale(int d_y){ if(d_y) { TModelUnit norm = m_StartNorm - ((TModelUnit) (d_y)) / m_PixPerNorm; norm = max(norm, m_MinNorm); norm = min(norm, m_MaxNorm); if(norm != m_CurrNorm) { m_CurrNorm = norm; TModelUnit scale = x_NormToScale(norm); m_pHost->MZHH_SetScale(scale, m_ptStart); } }}void CMouseZoomHandler::x_OnEndScale(EState new_state){ _ASSERT(new_state != eScale); m_State = new_state; m_StartNorm = m_CurrNorm; m_pHost->MZHH_Redraw(); }void CMouseZoomHandler::x_OnChangeZoomRectPan(int x, int y){ if(x != m_CurrPosX || y != m_CurrPosY) { m_CurrPosX = x; m_CurrPosY = y; m_pHost->MZHH_Redraw(); }}void CMouseZoomHandler::x_OnEndZoomRect(EState new_state){ m_State = new_state; TModelRect rc; int x1 = m_MouseStartX; int y1 = m_pHost->MZHH_GetVPPosByY(m_MouseStartY); int x2 = m_CurrPosX; int y2 = m_pHost->MZHH_GetVPPosByY(m_CurrPosY); rc.SetLeft(m_pPane->UnProjectX(min(x1, x2))); rc.SetRight(m_pPane->UnProjectX(max(x1, x2))); rc.SetBottom(m_pPane->UnProjectY(min(y1, y2))); rc.SetTop(m_pPane->UnProjectY(max(y1, y2))); m_pHost->MZHH_ZoomRect(rc); m_pHost->MZHH_Redraw(); }void CMouseZoomHandler::x_OnEndPan(EState new_state){ m_State = new_state; int y1 = m_pHost->MZHH_GetVPPosByY(m_MouseStartY); int y2 = m_pHost->MZHH_GetVPPosByY(m_CurrPosY); TModelUnit m_x1 = m_pPane->UnProjectX(m_MouseStartX); TModelUnit m_y1 = m_pPane->UnProjectY(y1); TModelUnit m_x2 = m_pPane->UnProjectX(m_CurrPosX); TModelUnit m_y2 = m_pPane->UnProjectY(y2); m_pHost->MZHH_Scroll(m_x1 - m_x2, m_y1 - m_y2); m_pHost->MZHH_Redraw(); }void CMouseZoomHandler::x_OnSelectCursor(void){ switch(m_State) { case eIdle: case eReadyScale: m_Cursor = FL_CURSOR_DEFAULT; break; case eScale: m_Cursor = FL_CURSOR_HAND; break; case eReadyPan: case ePan: m_Cursor = FL_CURSOR_MOVE; break; case eReadyZoomRect: case eZoomRect: m_Cursor = FL_CURSOR_CROSS; break; default: break; } //cout << "\nCMouseZoomHandler::x_OnSelectCursor " << m_Cursor; fl_cursor(m_Cursor, FL_BLACK, FL_WHITE);}/////////////////////////////////////////////////////////////////////////////////// helper functionsTModelUnit CMouseZoomHandler::x_ScaleToNorm(TModelUnit scale) const{ return log(scale);}TModelUnit CMouseZoomHandler::x_NormToScale(TModelUnit norm) const{ return exp(norm);}END_NCBI_SCOPE/* * =========================================================================== * $Log: mouse_zoom_handler.cpp,v $ * Revision 1000.3 2004/06/01 21:10:40 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10 2004/05/21 22:27:54 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.9 2004/03/26 15:03:48 yazhuk * Fixed stuff broken by previous changes * * Revision 1.8 2004/03/04 14:36:41 lebedev * Enable panning while mouse drag * * Revision 1.7 2004/03/02 21:54:52 yazhuk * Fixed CGlAttrGuard usage * * Revision 1.6 2004/02/17 15:23:01 yazhuk * Refactoring - replaced CGlParam with CGlAttrGuard * * Revision 1.5 2003/12/10 16:54:32 yazhuk * Added support for using mouse position to specify reference point for "active zoom". * * Revision 1.4 2003/12/08 15:12:48 yazhuk * Implemented deactivation on FL_UNFOCUS. * * Revision 1.3 2003/12/01 22:32:14 yazhuk * GCC ompilation fixes * * Revision 1.2 2003/12/01 16:41:30 yazhuk * Refactored event handling - introduced CGUIEvent; implemented zooming by * rectangle and panoraming. * * Revision 1.1 2003/11/17 20:24:51 yazhuk * Moved from widgets\aln_multiple * * Revision 1.3 2003/10/29 23:32:47 yazhuk * Updated includes * * Revision 1.2 2003/10/20 16:27:55 yazhuk * x_OnKeyUp() bug fix. * * Revision 1.1 2003/10/20 15:44:58 yazhuk * Initial revision. * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?