Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PreviewCameraTool.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
23 #ifdef _WIN32
24 #include "wx/msw/wrapwin.h"
25 #endif
26 #include "PreviewCameraTool.h"
27 #include "GLViewer.h"
28 
30 {
34  m_moving = false;
35 }
36 
37 void PreviewCameraTool::ChangeZoomLevel(bool zoomIn, const hugin_utils::FDiff2D& scrollPos)
38 {
40  if (zoomIn)
41  {
42  state->SetZoomLevel((state->GetZoomLevel()) * 1.2);
43  // update center to zoom in at given position
44  hugin_utils::FDiff2D newScrollPos;
45  newScrollPos.x = scrollPos.x / state->GetOptions()->getWidth();
46  newScrollPos.y = scrollPos.y / state->GetOptions()->getHeight();
47  state->SetViewingCenter(newScrollPos);
48  }
49  else
50  {
51  // out-zoom, keep current position
52  state->SetZoomLevel((state->GetZoomLevel()) / 1.2);
53  };
54  // redraw
55  state->ForceRequireRedraw();
56  state->Redraw();
57 }
58 
60 {
61  if (e.GetWheelRotation() != 0 && helper->IsMouseOverPano())
62  {
63  ChangeZoomLevel(e.GetWheelRotation() > 0, helper->GetMousePanoPosition());
64  }
65 }
66 
68 {
70  // move center by given distance
71  hugin_utils::FDiff2D currentCenter = state->GetViewingCenter();
72  currentCenter.x -= moveDist.x / state->GetOptions()->getWidth() / state->GetScale();
73  currentCenter.y -= moveDist.y / state->GetOptions()->getHeight() / state->GetScale();
74  state->SetViewingCenter(currentCenter);
75  state->SetDirtyViewport();
76  state->ForceRequireRedraw();
77  state->Redraw();
78 }
79 
81 {
82  // listen only to middle button events
83  if (!m_moving && e.MiddleDown())
84  {
85  if (helper->IsMouseOverPano())
86  {
87  // start dragging
88  m_moving = true;
90  };
91  }
92  else
93  {
94  if (m_moving && e.MiddleUp())
95  {
96  // end dragging, update center
97  m_moving = false;
98  if (helper->IsMouseOverPano())
99  {
101  };
102  };
103  };
104 }
105 
106 void PreviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent& e)
107 {
108  if (m_moving)
109  {
110  // mouse is moving, if middle mouse button is pressed update center in real time
111  if (e.MiddleIsDown())
112  {
113  if (helper->IsMouseOverPano())
114  {
115  const hugin_utils::FDiff2D currentPos = helper->GetMouseScreenPosition();
116  const hugin_utils::FDiff2D diffPos = currentPos - m_lastScreenPos;
117  if (diffPos.squareLength() > 100)
118  {
119  // update only when mouse moved at least 10 pixel
120  UpdateCenter(diffPos);
121  m_lastScreenPos = currentPos;
122  };
123  };
124  }
125  else
126  {
127  // we are still moving, but middle button is not pressed any more
128  // so reset moving bit
129  m_moving = false;
130  };
131  };
132 }
hugin_utils::FDiff2D GetMousePanoPosition()
Definition: ToolHelper.cpp:295
hugin_utils::FDiff2D GetViewingCenter() const
Definition: ViewState.h:232
void Activate()
Switch on a tool.
unsigned int getHeight() const
get panorama height
void ForceRequireRedraw()
Definition: ViewState.cpp:439
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
void MouseButtonEvent(wxMouseEvent &e)
event for mouse button processing
void MouseWheelEvent(wxMouseEvent &)
event for mouse wheel processing
void MouseMoveEvent(double x, double y, wxMouseEvent &e)
event for mouse move
double GetZoomLevel() const
Definition: ViewState.h:227
VisualizationState * GetVisualizationStatePtr()
Definition: ToolHelper.cpp:300
void UpdateCenter(const hugin_utils::FDiff2D &moveDist)
update center, used for panning
hugin_utils::FDiff2D GetMouseScreenPosition()
Definition: ToolHelper.cpp:290
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition: Tool.h:102
bool m_moving
flag to indicate that we are moving the view with middle mouse button
bool IsMouseOverPano()
Definition: ToolHelper.h:136
hugin_utils::FDiff2D m_lastScreenPos
last screen position during moving , needed for real-time update
T squareLength() const
Return the square of the length of the vector.
Definition: hugin_math.h:141
void SetViewingCenter(const hugin_utils::FDiff2D &center)
Definition: ViewState.cpp:493
unsigned int getWidth() const
virtual HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:468
void SetDirtyViewport()
Definition: ViewState.h:249
void SetZoomLevel(const float new_zoom)
Definition: ViewState.cpp:483
void ChangeZoomLevel(bool zoomIn, const hugin_utils::FDiff2D &scrollPos)
update zoom level