📄 mouse_zoom_handler.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: mouse_zoom_handler.hpp,v $ * PRODUCTION Revision 1000.2 2004/04/12 18:16:34 gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.4 * PRODUCTION * =========================================================================== */#ifndef __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP#define __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP/* $Id: mouse_zoom_handler.hpp,v 1000.2 2004/04/12 18:16:34 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Andrey Yazhuk * * File Description: * */#include <corelib/ncbistl.hpp>#include <gui/widgets/gl/ievent_handler.hpp>#include <gui/opengl/glbitmapfont.hpp>#include <gui/opengl/glpane.hpp>#include <gui/opengl/glcolor.hpp>#include <math.h>BEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////////// Interface IMouseZoomHandlerHost represents a context in which CMouseZoomHandler/// functions. class NCBI_GUIWIDGETS_GL_EXPORT IMouseZoomHandlerHost{public: enum EScaleType { eMin, /// minimal scale eCurrent, /// current scale eMax, /// maximal scale }; virtual ~IMouseZoomHandlerHost() {} virtual TModelUnit MZHH_GetScale(EScaleType type) = 0; virtual void MZHH_SetScale(TModelUnit scale, const TModelPoint& point) = 0; virtual void MZHH_ZoomRect(const TModelRect& rc) = 0; virtual void MZHH_Scroll(TModelUnit d_x, TModelUnit d_y) = 0; /// converts FLTK window coord to Viewport coord virtual TVPUnit MZHH_GetVPPosByY(int y) const = 0; /// redraws the Host and the handler virtual void MZHH_Redraw(void) = 0;};/////////////////////////////////////////////////////////////////////////////////// CMouseZoomHandler is an event handler that allows to zoom its Host component/// using mouse.class NCBI_GUIWIDGETS_GL_EXPORT CMouseZoomHandler : public IEventHandler{public: CMouseZoomHandler(); virtual ~CMouseZoomHandler(); void SetHost(IMouseZoomHandlerHost* pHost); void Render(CGlPane& Pane); /// IEventHandler implementation. virtual int handle(CGUIEvent& event, CGlPane& Pane); protected: /// user event handlers - translate event to signals int x_OnMousePush(CGUIEvent& event); int x_OnMouseDrag(CGUIEvent& event); int x_OnMouseRelease(CGUIEvent& event); int x_OnMouseMove(void); int x_OnMouseWheel(CGUIEvent& event); int x_OnKeyDown(CGUIEvent& event); int x_OnKeyUp(CGUIEvent& event); enum EState { eIdle, eReadyScale, eReadyZoomRect, eReadyPan, eScale, eZoomRect, ePan }; /// signal handlers - functions doing the real job void x_SwitchToReadyState(EState new_state, int pos_x, int pos_y); void x_SwithToActiveState(EState state, int pos_x, int pos_y); void x_OnChangeScale(int d_y); void x_OnEndScale(EState new_state); void x_OnChangeZoomRectPan(int x, int y); void x_OnEndZoomRect(EState new_state); void x_OnEndPan(EState new_state); void x_OnChangePan(); protected: // helper functions void x_OnSelectCursor(void); TModelUnit x_ScaleToNorm(TModelUnit scale) const; TModelUnit x_NormToScale(TModelUnit norm) const; int x_NormToPixels(TModelUnit norm) const; void x_RenderScale(CGlPane& pane); void x_RenderZoomRect(CGlPane& pane); void x_RenderPan(CGlPane& pane); void x_DrawTicks(int center_x, int y, int tick_w); void x_DrawMarker(int x_c, int y_c, int half); const IMouseZoomHandlerHost* x_GetHost(void) const { return m_pHost; } IMouseZoomHandlerHost* x_GetHost(void) { return m_pHost; }protected: IMouseZoomHandlerHost* m_pHost; CGlPane* m_pPane; EState m_State; Fl_Cursor m_Cursor; // Members used in "Scale" mode int m_PixPerNorm; TModelUnit m_MaxNorm; TModelUnit m_MinNorm; TModelUnit m_StartNorm; TModelUnit m_CurrNorm; // current norm value int m_MarkerPosX, m_MarkerPosY; // point where marker is drawn int m_MouseStartX; int m_MouseStartY; int m_CurrPosX; int m_CurrPosY; // mouse position corresponding to m_CurrNurm; TModelPoint m_ptStart; // referrence point for Zoom int m_WheelTotalShift; // scale in logarihtnic units CGlColor m_ScaleColor; CGlColor m_TickColor; CGlColor m_RectColor;};END_NCBI_SCOPE/* * =========================================================================== * $Log: mouse_zoom_handler.hpp,v $ * Revision 1000.2 2004/04/12 18:16:34 gouriano * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.4 * * Revision 1.4 2004/03/04 14:36:12 lebedev * Enable panning while mouse drag * * Revision 1.3 2003/12/10 16:54:16 yazhuk * Added support for using mouse position to specify reference point for "active zoom". * * Revision 1.2 2003/12/01 16:41:44 yazhuk * Refactored event handling - introduced CGUIEvent; implemented zooming by * rectangle and panoraming. * * Revision 1.1 2003/11/17 20:23:22 yazhuk * Moved from widgets\aln_multiple * * Revision 1.1 2003/10/20 15:44:47 yazhuk * Initial revision. * * =========================================================================== */#endif // __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -