From: <hug...@li...> - 2011-02-26 21:13:22
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/f9ed69690aec changeset: 4987:f9ed69690aec user: dmakreshanski <dma...@us...> date: Sat Feb 26 21:15:23 2011 +0100 description: added support for zooming in and out in overview with keyboard, but not really usable until tools handle keyboard events not only from the GLCanvas but also globally from the frame as well. diffstat: src/hugin1/hugin/GLPreviewFrame.cpp | 49 ++++++++++++++++++++++++ src/hugin1/hugin/GLPreviewFrame.h | 3 + src/hugin1/hugin/OverviewCameraTool.cpp | 74 +++++++++++++++++++++++++++--------- src/hugin1/hugin/OverviewCameraTool.h | 5 ++ 4 files changed, 112 insertions(+), 19 deletions(-) diffs (220 lines): diff -r 067870ab0d9b -r f9ed69690aec src/hugin1/hugin/GLPreviewFrame.cpp --- a/src/hugin1/hugin/GLPreviewFrame.cpp Fri Feb 18 18:15:50 2011 +0100 +++ b/src/hugin1/hugin/GLPreviewFrame.cpp Sat Feb 26 21:15:23 2011 +0100 @@ -118,6 +118,9 @@ BEGIN_EVENT_TABLE(GLPreviewFrame, wxFrame) EVT_CLOSE(GLPreviewFrame::OnClose) EVT_SHOW(GLPreviewFrame::OnShowEvent) + //for some reason only key up is sent, key down event is not sent +// EVT_KEY_DOWN(GLPreviewFrame::KeyDown) +// EVT_KEY_UP(GLPreviewFrame::KeyUp) EVT_BUTTON(XRCID("preview_center_tool"), GLPreviewFrame::OnCenterHorizontally) EVT_BUTTON(XRCID("preview_fit_pano_tool"), GLPreviewFrame::OnFitPano) EVT_BUTTON(XRCID("preview_fit_pano_tool2"), GLPreviewFrame::OnFitPano) @@ -1131,6 +1134,52 @@ } +//the following methods are to substitude the GLViewer KeyUp and KeyDown methods +//so that tools use key events that happen globally to the preview frame +//however only key up event is sent, and not key down +//so until this is resolved they will remain to be handled by GLViewer +void GLPreviewFrame::KeyDown(wxKeyEvent& e) +{ + if (preview_helper) { + preview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), true); + } + if (m_OverviewToggle->GetValue()) { + if(m_GLOverview->GetMode() == GLOverview::PLANE) { + if (plane_overview_helper) { + plane_overview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), true); + } + } else if (m_GLOverview->GetMode() == GLOverview::PANOSPHERE) { + if (panosphere_overview_helper) { + panosphere_overview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), true); + } + } + + } + e.Skip(); +} + +void GLPreviewFrame::KeyUp(wxKeyEvent& e) +{ + if (preview_helper) { + preview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), false); + } + if (m_OverviewToggle->GetValue()) { + if(m_GLOverview->GetMode() == GLOverview::PLANE) { + if (plane_overview_helper) { + plane_overview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), false); + } + } else if (m_GLOverview->GetMode() == GLOverview::PANOSPHERE) { + if (panosphere_overview_helper) { + panosphere_overview_helper->KeypressEvent(e.GetKeyCode(), e.GetModifiers(), false); + } + } + + } + e.Skip(); +} + + + void GLPreviewFrame::OnOverviewToggle(wxCommandEvent& e) { DEBUG_TRACE("overview toggle"); diff -r 067870ab0d9b -r f9ed69690aec src/hugin1/hugin/GLPreviewFrame.h --- a/src/hugin1/hugin/GLPreviewFrame.h Fri Feb 18 18:15:50 2011 +0100 +++ b/src/hugin1/hugin/GLPreviewFrame.h Sat Feb 26 21:15:23 2011 +0100 @@ -273,6 +273,9 @@ void OnBlendChoice(wxCommandEvent & e); void OnDragChoice(wxCommandEvent & e); + void KeyDown(wxKeyEvent & e); + void KeyUp(wxKeyEvent & e); + void OnCustomDragChoice(wxCommandEvent & e); void DragChoiceLayout( int index ); diff -r 067870ab0d9b -r f9ed69690aec src/hugin1/hugin/OverviewCameraTool.cpp --- a/src/hugin1/hugin/OverviewCameraTool.cpp Fri Feb 18 18:15:50 2011 +0100 +++ b/src/hugin1/hugin/OverviewCameraTool.cpp Sat Feb 26 21:15:23 2011 +0100 @@ -32,9 +32,12 @@ helper->NotifyMe(ToolHelper::MOUSE_MOVE, this); helper->NotifyMe(ToolHelper::MOUSE_PRESS, this); helper->NotifyMe(ToolHelper::MOUSE_WHEEL, this); + helper->NotifyMe(ToolHelper::KEY_PRESS, this); down = false; } + + void PanosphereOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e) { if (down) { @@ -72,12 +75,18 @@ } } -void PanosphereOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e) -{ - double scale = 1.1; + +void PanosphereOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) { PanosphereOverviewVisualizationState* state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr(); double radius = state->getSphereRadius(); - if (e.GetWheelRotation() < 0) { + if (zoomIn) { + if (state->getR() > limit_low * radius) { + state->setR((state->getR() - radius) / scale + radius); + state->SetDirtyViewport(); + state->ForceRequireRedraw(); + state->Redraw(); + } + } else { if (state->getR() < limit_high * radius) { state->setR((state->getR() - radius) * scale + radius); state->SetDirtyViewport(); @@ -85,17 +94,29 @@ state->Redraw(); } } - if (e.GetWheelRotation() > 0) { - if (state->getR() > limit_low * radius) { - state->setR((state->getR() - radius) / scale + radius); - state->SetDirtyViewport(); - state->ForceRequireRedraw(); - state->Redraw(); +} + +void PanosphereOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e) +{ + if (e.GetWheelRotation() != 0) { + ChangeZoomLevel(e.GetWheelRotation() > 0); + } +} + +void PanosphereOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) { +// std::cout << "kc: " << keycode << " " << modifiers << std::endl; +// std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_ADD << " " << WXK_SUBTRACT << std::endl; +// std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_NUMPAD_ADD << " " << WXK_NUMPAD_SUBTRACT << std::endl; + if (pressed) + if (modifiers == wxMOD_CMD) { + if (keycode == WXK_ADD) { + ChangeZoomLevel(true); + } else if (keycode == WXK_SUBTRACT) { + ChangeZoomLevel(false); } } } - void PlaneOverviewCameraTool::Activate() { helper->NotifyMe(ToolHelper::MOUSE_MOVE, this); @@ -168,19 +189,34 @@ } } - -void PlaneOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e) -{ - double scale = 1.1; +void PlaneOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) { PlaneOverviewVisualizationState* state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr(); - if (e.GetWheelRotation() < 0) { + if (zoomIn) { + state->setR(state->getR() / scale); + } else { state->setR(state->getR() * scale); } - if (e.GetWheelRotation() > 0) { - state->setR(state->getR() / scale); - } state->SetDirtyViewport(); state->ForceRequireRedraw(); state->Redraw(); } +void PlaneOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e) +{ + if (e.GetWheelRotation() != 0) { + ChangeZoomLevel(e.GetWheelRotation() > 0); + } +} + +void PlaneOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) { + if (pressed) + if (modifiers == wxMOD_CMD) { + if (keycode == WXK_ADD) { + ChangeZoomLevel(true); + } else if (keycode == WXK_SUBTRACT) { + ChangeZoomLevel(false); + } + } +} + + diff -r 067870ab0d9b -r f9ed69690aec src/hugin1/hugin/OverviewCameraTool.h --- a/src/hugin1/hugin/OverviewCameraTool.h Fri Feb 18 18:15:50 2011 +0100 +++ b/src/hugin1/hugin/OverviewCameraTool.h Sat Feb 26 21:15:23 2011 +0100 @@ -45,6 +45,8 @@ void MouseButtonEvent(wxMouseEvent &e); void MouseWheelEvent(wxMouseEvent &); + void ChangeZoomLevel(bool zoomIn, double scale = 1.1); + void KeypressEvent(int keycode, int modifiers, bool pressed); private: @@ -77,6 +79,9 @@ void MouseMoveEvent(double x, double y, wxMouseEvent & e); void MouseButtonEvent(wxMouseEvent &e); void MouseWheelEvent(wxMouseEvent &); + + void ChangeZoomLevel(bool zoomIn, double scale = 1.1); + void KeypressEvent(int keycode, int modifiers, bool pressed); private: |