NCBI C++ ToolKit
mouse_zoom_handler.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP
2 #define __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP
3 
4 /* $Id: mouse_zoom_handler.hpp 42213 2019-01-11 21:00:33Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 
38 
39 #include <gui/utils/rgba_color.hpp>
40 
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Interface IMouseZoomHandlerHost represents a context in which CMouseZoomHandler
45 /// functions.
46 
48 
49 {
50 public:
51  enum EScaleType {
52  eMin, /// minimal scale
53  eCurrent, /// current scale
54  eMax /// maximal scale
55  };
56 
58  virtual void MZHH_SetScale(TModelUnit scale, const TModelPoint& point) = 0;
59  virtual void MZHH_ZoomPoint(const TModelPoint& point, TModelUnit factor) = 0;
60  virtual void MZHH_ZoomRect(const TModelRect& rc) = 0;
61  virtual void MZHH_Scroll(TModelUnit d_x, TModelUnit d_y) = 0;
62 
63  // indicates that an operation has ended and results can be posted to the history
64  virtual void MZHH_EndOp() = 0;
65 
66  /// converts window coord to Viewport coord
67  virtual TVPUnit MZHH_GetVPPosByY(int y) const = 0;
68 
70 };
71 
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// CMouseZoomHandler provides support for mouse-driven zoom and pan operations.
76  public wxEvtHandler,
77  public IGlEventHandler
78 {
79  DECLARE_EVENT_TABLE()
80 public:
81  enum EMode {
84  e2D
85  };
86 
87  enum EPanMode {
89  ePkey
90  };
91 
93  virtual ~CMouseZoomHandler();
94 
95  virtual void SetMode(EMode mode);
96  virtual void SetHost(IMouseZoomHandlerHost* pHost);
97  virtual IGenericHandlerHost* GetGenericHost();
98  virtual void Render(CGlPane& Pane);
99  virtual void SetPanMode(EPanMode mode) { m_PanMode = mode; }
100  virtual EPanMode GetPanMode() const { return m_PanMode; }
101  virtual void SetPanOnMouseDown(bool b) { m_PanOnMouseDown = b; }
102  virtual bool IsScaleMode() const { return (m_State==eScale || m_State==eReadyScale); }
103 
104  /// @name IGlEventHandler implementaion
105  /// @{
106  virtual void SetPane(CGlPane* pane);
107  virtual wxEvtHandler* GetEvtHandler();
108  /// @}
109 
110  /// @name wxWidgets event handling
111  /// @{
112  void OnLeftDown(wxMouseEvent& event);
113  void OnLeftUp(wxMouseEvent& event);
114  void OnMotion(wxMouseEvent& event);
115  void OnMouseWheel(wxMouseEvent& event);
116  void OnOtherMouseEvents(wxMouseEvent& event);
117  void OnMiddleDown(wxMouseEvent& event);
118  void OnMiddleUp(wxMouseEvent& event);
119  void OnMouseCaptureLost(wxMouseCaptureLostEvent& evt);
120  void OnKeyDown(wxKeyEvent& event);
121  void OnKeyUp(wxKeyEvent& event);
122  void OnKillFocus(wxFocusEvent& event);
123  /// @}
124 
125 protected:
126  enum EKeyState {
130  eZoomRectState
131  };
132 
133  enum EState {
140  ePan
141  };
142 
143  EKeyState x_GetKeyState();
144  EKeyState x_GetKeyState(wxKeyEvent& event);
145 
146  void x_OnCancel();
147 
148  /// signal handlers - functions doing the real job
149  void x_SwitchToReadyState(EState new_state, const wxPoint& ms_pos);
150  void x_SwitchToActiveState(EState state, const wxPoint& ms_pos);
151 
152  void x_OnChangeScale(int d_y);
153  void x_OnEndScale(EState new_state);
154 
155  void x_OnChangeZoomRectPan(const wxPoint& pos);
156  void x_OnEndZoomRect(EState new_state);
157  void x_OnEndPan(EState new_state);
158  void x_OnChangePan(const wxPoint& ms_pos);
159 
160 protected:
161  // helper functions
162  void x_OnSelectCursor(void);
163 
164  TModelUnit x_ScaleToNorm(TModelUnit scale) const;
165  TModelUnit x_NormToScale(TModelUnit norm) const;
166  int x_NormToPixels(TModelUnit norm) const;
167 
168  void x_RenderScale(CGlPane& pane);
169  void x_RenderZoomRect(CGlPane& pane);
170  void x_RenderPan(CGlPane& pane);
171 
172  void x_DrawTicks(int center_x, int y, int tick_w);
173  void x_DrawMarker(bool fill, int x_c, int y_c, int half);
174 
175  const IMouseZoomHandlerHost* x_GetHost(void) const { return m_Host; }
176  IMouseZoomHandlerHost* x_GetHost(void) { return m_Host; }
177 
178  void x_CaptureMouse();
179  void x_ReleaseMouse();
180 
181 protected:
185 
187  wxStockCursor m_CursorId;
189  bool m_PanOnMouseDown; // start pan on down instead of after moving.
190 
191  // Members used in "Scale" mode
197  TModelUnit m_CurrNorm; // current norm value
198 
199  wxPoint m_MarkerPos; // point where marker is drawn
200 
201  wxPoint m_CurrMouse; // current mouse position
202 
203  wxPoint m_MouseStart;
204  wxPoint m_CurrPos; // mouse position corresponding to m_CurrNurm;
205  TModelPoint m_ptStart; // referrence point for Zoom
206 
207  bool m_HasCapture; // indicated whether the handler has Mouse Capture on the host
208 
210 
211  // scale in logarithmic units
215 };
216 
217 
219 
220 #endif // __GUI_WIDGETS_GL___MOUSE_ZOOM_HANDLER__HPP
class CGlPane
Definition: glpane.hpp:62
CMouseZoomHandler provides support for mouse-driven zoom and pan operations.
IMouseZoomHandlerHost * m_Host
virtual void SetPanMode(EPanMode mode)
virtual void SetPanOnMouseDown(bool b)
virtual bool IsScaleMode() const
virtual EPanMode GetPanMode() const
const IMouseZoomHandlerHost * x_GetHost(void) const
IMouseZoomHandlerHost * x_GetHost(void)
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
IGenericHandlerHost.
IGlEventHandler.
Interface IMouseZoomHandlerHost represents a context in which CMouseZoomHandler functions.
virtual void MZHH_ZoomRect(const TModelRect &rc)=0
virtual void MZHH_ZoomPoint(const TModelPoint &point, TModelUnit factor)=0
virtual void MZHH_SetScale(TModelUnit scale, const TModelPoint &point)=0
virtual TVPUnit MZHH_GetVPPosByY(int y) const =0
converts window coord to Viewport coord
virtual void MZHH_EndOp()=0
virtual TModelUnit MZHH_GetScale(EScaleType type)=0
virtual void MZHH_Scroll(TModelUnit d_x, TModelUnit d_y)=0
GLdouble TModelUnit
Definition: gltypes.hpp:48
int TVPUnit
Definition: gltypes.hpp:47
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_GL_EXPORT
Definition: gui_export.h:529
mdb_mode_t mode
Definition: lmdb++.h:38
The NCBI C++/STL use hints.
Definition: type.c:6
Modified on Mon Mar 04 05:12:47 2024 by modify_doxy.py rev. 669887