From 8dc92596e5402e8bb064bcacb47979c429564c42 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Mon, 28 Feb 2011 16:39:10 +0100 Subject: [PATCH] ENH: Allow for other key mapping --- .../otbArrowKeyMoveActionHandler.h | 281 ++++++++++-------- 1 file changed, 155 insertions(+), 126 deletions(-) diff --git a/Code/Visualization/otbArrowKeyMoveActionHandler.h b/Code/Visualization/otbArrowKeyMoveActionHandler.h index 00b180803a..f748e7fa42 100644 --- a/Code/Visualization/otbArrowKeyMoveActionHandler.h +++ b/Code/Visualization/otbArrowKeyMoveActionHandler.h @@ -81,150 +81,167 @@ public: sourceWidget = m_View->GetZoomWidget(); handle = true; } + if(handle && event == FL_FOCUS) + { + return true; + } if ((handle) && ((event == FL_KEYBOARD) || (event == FL_SHORTCUT))) { - switch (Fl::event_key()) + // handle compose mode + if(m_Composed && Fl::event_state() != (int)m_ComposeKey) + { + return false; + } + + unsigned int eventKey = Fl::event_key(); + + if(eventKey == m_UpKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[1] -= size[1]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_DownKey) { - case FL_Up: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[1] -= size[1]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Down: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[1] += size[1]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Left: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[0] -= size[0]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Right: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[0] += size[0]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - default: - { - return false; - break; - } + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[1] += size[1]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_LeftKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[0] -= size[0]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_RightKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[0] += size[0]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; } } } return false; } - /** Set/Get the pointer to the model */ +/** Set/Get the pointer to the model */ itkSetObjectMacro(Model, ModelType); itkGetObjectMacro(Model, ModelType); - /** Set/Get the pointer to the view */ +/** Set/Get the pointer to the view */ itkSetObjectMacro(View, ViewType); itkGetObjectMacro(View, ViewType); +/** Set key mapping */ + itkSetMacro(UpKey,unsigned int); + itkGetMacro(UpKey,unsigned int); + itkSetMacro(DownKey,unsigned int); + itkGetMacro(DownKey,unsigned int); + itkSetMacro(LeftKey,unsigned int); + itkGetMacro(LeftKey,unsigned int); + itkSetMacro(RightKey,unsigned int); + itkGetMacro(RightKey,unsigned int); + itkSetMacro(Composed,bool); + itkGetMacro(Composed,bool); + itkSetMacro(ComposeKey,unsigned int); + itkGetMacro(ComposeKey,unsigned int); + protected: - /** Constructor */ - ArrowKeyMoveActionHandler() : m_View(), m_Model() +/** Constructor */ + ArrowKeyMoveActionHandler() : m_View(), m_Model(), + m_UpKey(FL_Up), m_DownKey(FL_Down), + m_LeftKey(FL_Left),m_RightKey(FL_Right), + m_Composed(false), m_ComposeKey(FL_SHIFT) {} - /** Destructor */ +/** Destructor */ virtual ~ArrowKeyMoveActionHandler(){} - /** Printself method */ +/** Printself method */ void PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); @@ -234,12 +251,24 @@ private: ArrowKeyMoveActionHandler(const Self&); // purposely not implemented void operator =(const Self&); // purposely not implemented - // Pointer to the view +// Pointer to the view ViewPointerType m_View; - // Pointer to the model +// Pointer to the model ModelPointerType m_Model; +// Key mapping for up,down,left and right + unsigned int m_UpKey; + unsigned int m_DownKey; + unsigned int m_LeftKey; + unsigned int m_RightKey; + + // Use composed shortcuts + bool m_Composed; + +// Key state (for Ctrl - shortcuts) + unsigned int m_ComposeKey; + }; // end class } // end namespace otb #endif -- GitLab