Orfeo Toolbox  3.16
otbImageViewerZoomWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbImageViewerZoomWidget_h
19 #define __otbImageViewerZoomWidget_h
20 
21 #include "vcl_deprecated_header.h"
22 
23 #include "otbZoomableImageWidget.h"
25 #include "otbImageWidgetBoxForm.h"
27 #include <FL/fl_draw.H>
28 
29 namespace otb
30 {
31 template <class TPixel, class TLabel> class ImageViewerBase;
45 template <class TPixel, class TLabel>
47  : public ZoomableImageWidget<TPixel>
48 {
49 public:
55 
57  itkNewMacro(Self);
58 
61 
62  typedef TPixel PixelType;
63  typedef TLabel LabelType;
64  typedef typename Superclass::IndexType IndexType;
65  typedef typename Superclass::SizeType SizeType;
66 
69 
70  itkSetMacro(Parent, ParentPointerType);
71  itkGetMacro(Parent, ParentPointerType);
73  virtual int handle(int event)
74  {
75  switch (event)
76  {
77  case FL_ENTER:
78  {
79  m_MouseIn = true;
80  return 1;
81  }
82  case FL_LEAVE:
83  {
84  m_MouseIn = false;
85  m_Parent->UpdateZoomWidget();
86  m_Parent->ClearPixLocVal();
87  return 1;
88  }
89  case FL_MOVE:
90  {
91  m_MouseIn = true;
92  if (m_MouseMoveCount % m_ValueUpdateFrequency == 0)
93  {
94  m_MousePos[0] = Fl::event_x();
95  m_MousePos[1] = Fl::event_y();
96  IndexType newIndex = this->WindowToImageCoordinates(m_MousePos);
97  m_Parent->ReportPixel(newIndex);
98  m_MouseMoveCount = 0;
99  }
100  m_MouseMoveCount++;
101  return 1;
102  }
103  case FL_MOUSEWHEEL:
104  {
105  int dy = Fl::event_dy();
106  if (dy < 0)
107  {
108  this->SetZoomFactor(this->GetOpenGlIsotropicZoom() + m_ZoomStep);
109  }
110  else
111  {
112  if (this->GetOpenGlIsotropicZoom() - m_ZoomStep >= 1)
113  {
114  this->SetZoomFactor(this->GetOpenGlIsotropicZoom() - m_ZoomStep);
115  }
116  else
117  {
118  this->SetZoomFactor(1.0);
119  }
120  }
121  m_Parent->Update();
122  return 1;
123  }
124  case FL_FOCUS:
125  {
126  return 1;
127  }
128  case FL_UNFOCUS:
129  {
130  return 1;
131  }
132  case FL_KEYDOWN:
133  {
134  IndexType newIndex = this->GetViewedRegion().GetIndex();
135  SizeType newSize = this->GetViewedRegion().GetSize();
136  newIndex[0] = newIndex[0] + newSize[0] / 2;
137  newIndex[1] = newIndex[1] + newSize[1] / 2;
138  switch (Fl::event_key())
139  {
140  case FL_Down:
141  {
142  newIndex[1] = newIndex[1] + newSize[1] / 8;
143  break;
144  }
145  case FL_Up:
146  {
147  newIndex[1] = newIndex[1] - newSize[1] / 8;
148  break;
149  }
150  case FL_Left:
151  {
152  newIndex[0] = newIndex[0] - newSize[0] / 8;
153  break;
154  }
155  case FL_Right:
156  {
157  newIndex[0] = newIndex[0] + newSize[0] / 8;
158  break;
159  }
160  }
161  m_Parent->ChangeZoomViewedRegion(newIndex);
162  return 1;
163  }
164  }
165  return 0;
166  }
167 
168  virtual void resize(int x, int y, int w, int h)
169  {
170  Superclass::resize(x, y, w, h);
171  if (m_Parent->GetBuilt()) m_Parent->Update();
172  }
173 
174 protected:
179  {
180  m_ZoomStep = 0.2;
181  m_MouseIn = false;
182  m_MousePos.Fill(0);
183  m_MouseMoveCount = 0;
184  m_ValueUpdateFrequency = 5;
185  };
190  {
191  m_Parent = NULL;
192  }
193 
194 private:
196  double m_ZoomStep;
198  bool m_MouseIn;
199  unsigned int m_MouseMoveCount;
201 
202 };
203 
204 } // end namespace otb
205 #endif

Generated at Sun Feb 3 2013 00:31:19 for Orfeo Toolbox with doxygen 1.8.1.1