| 183 | } |
| 184 | |
| 185 | bool ConsoleApp::HandleInputEvent(ftxui::Event& e) |
| 186 | { |
| 187 | META_FUNCTION_TASK(); |
| 188 | if (!e.is_mouse()) |
| 189 | return false; |
| 190 | |
| 191 | if (e.mouse().button == ftxui::Mouse::Button::Left) |
| 192 | { |
| 193 | const data::Point2I mouse_current_pos(e.mouse().x, e.mouse().y); |
| 194 | if (m_mouse_pressed_pos.has_value()) |
| 195 | { |
| 196 | const data::Point2I shift = (*m_mouse_pressed_pos - mouse_current_pos) * 2; |
| 197 | m_frame_rect.origin.SetX(std::max(0, std::min(m_frame_pressed_pos->GetX() + shift.GetX(), |
| 198 | static_cast<int32_t>(m_field_size.GetWidth() - m_frame_rect.size.GetWidth() - 1)))); |
| 199 | m_frame_rect.origin.SetY(std::max(0, std::min(m_frame_pressed_pos->GetY() + shift.GetY(), |
| 200 | static_cast<int32_t>(m_field_size.GetHeight() - m_frame_rect.size.GetHeight() - 1)))); |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | m_mouse_pressed_pos = mouse_current_pos; |
| 205 | m_frame_pressed_pos = m_frame_rect.origin; |
| 206 | } |
| 207 | } |
| 208 | else if (m_mouse_pressed_pos.has_value()) |
| 209 | { |
| 210 | m_mouse_pressed_pos.reset(); |
| 211 | m_frame_pressed_pos.reset(); |
| 212 | } |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | } // namespace Methane::Tutorials |