From d685a8655e498dce26fd8883321f81132c6f026f Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 18 Apr 2021 18:42:42 +0200 Subject: [PATCH] Parse mouse middle --- examples/util/print_key_press.cpp | 8 ++++++++ include/ftxui/component/event.hpp | 6 ++++++ src/ftxui/component/event.cpp | 20 ++++++++++++++++++- src/ftxui/component/terminal_input_parser.cpp | 15 ++++++++++++++ src/ftxui/component/terminal_input_parser.hpp | 2 ++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/examples/util/print_key_press.cpp b/examples/util/print_key_press.cpp index 35ef936..3cfd57f 100644 --- a/examples/util/print_key_press.cpp +++ b/examples/util/print_key_press.cpp @@ -41,6 +41,14 @@ class DrawKey : public Component { code += L"mouse_left_move(" + // std::to_wstring(keys[i].mouse_x()) + L"," + std::to_wstring(keys[i].mouse_y()) + L")"; + } else if (keys[i].is_mouse_middle_down()) { + code += L"mouse_middle_down(" + // + std::to_wstring(keys[i].mouse_x()) + L"," + + std::to_wstring(keys[i].mouse_y()) + L")"; + } else if (keys[i].is_mouse_middle_move()) { + code += L"mouse_middle_move(" + // + std::to_wstring(keys[i].mouse_x()) + L"," + + std::to_wstring(keys[i].mouse_y()) + L")"; } else if (keys[i].is_mouse_right_down()) { code += L"mouse_right_down(" + // std::to_wstring(keys[i].mouse_x()) + L"," + diff --git a/include/ftxui/component/event.hpp b/include/ftxui/component/event.hpp index 40ab123..833ac7d 100644 --- a/include/ftxui/component/event.hpp +++ b/include/ftxui/component/event.hpp @@ -32,6 +32,8 @@ struct Event { static Event MouseUp(std::string, int x, int y); static Event MouseLeftMove(std::string, int x, int y); static Event MouseLeftDown(std::string, int x, int y); + static Event MouseMiddleMove(std::string, int x, int y); + static Event MouseMiddleDown(std::string, int x, int y); static Event MouseRightMove(std::string, int x, int y); static Event MouseRightDown(std::string, int x, int y); @@ -59,6 +61,8 @@ struct Event { bool is_mouse_left_down() const { return type_ == Type::MouseLeftDown; } bool is_mouse_left_move() const { return type_ == Type::MouseLeftMove; } + bool is_mouse_middle_down() const { return type_ == Type::MouseMiddleDown; } + bool is_mouse_middle_move() const { return type_ == Type::MouseMiddleMove; } bool is_mouse_right_down() const { return type_ == Type::MouseRightDown; } bool is_mouse_right_move() const { return type_ == Type::MouseRightMove; } bool is_mouse_up() const { return type_ == Type::MouseUp; } @@ -79,6 +83,8 @@ struct Event { MouseUp, MouseLeftDown, MouseLeftMove, + MouseMiddleDown, + MouseMiddleMove, MouseRightDown, MouseRightMove, }; diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index 5dc9e77..d55d46b 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -73,6 +73,22 @@ Event Event::MouseRightDown(std::string input, int x, int y) { return event; } +// static +Event Event::MouseMiddleMove(std::string input, int x, int y) { + Event event; + event.input_ = std::move(input); + event.type_ = Type::MouseMiddleMove; + event.mouse_ = {x, y}; + return event; +} + +// static +Event Event::Special(std::string input) { + Event event; + event.input_ = std::move(input); + return event; +} + // static Event Event::MouseRightMove(std::string input, int x, int y) { Event event; @@ -83,9 +99,11 @@ Event Event::MouseRightMove(std::string input, int x, int y) { } // static -Event Event::Special(std::string input) { +Event Event::MouseMiddleDown(std::string input, int x, int y) { Event event; event.input_ = std::move(input); + event.type_ = Type::MouseMiddleDown; + event.mouse_ = {x, y}; return event; } diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index de73bd5..f348aeb 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -66,6 +66,16 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) { output.mouse.y)); break; + case MOUSE_MIDDLE_DOWN: + out_->Send(Event::MouseMiddleDown(std::move(pending_), output.mouse.x, + output.mouse.y)); + break; + + case MOUSE_MIDDLE_MOVE: + out_->Send(Event::MouseMiddleMove(std::move(pending_), output.mouse.x, + output.mouse.y)); + break; + case MOUSE_RIGHT_DOWN: out_->Send(Event::MouseRightDown(std::move(pending_), output.mouse.x, output.mouse.y)); @@ -211,6 +221,11 @@ TerminalInputParser::Output TerminalInputParser::ParseMouse( case 64: return Output(MOUSE_LEFT_MOVE, arguments[1], arguments[2]); + case 33: + return Output(MOUSE_MIDDLE_DOWN, arguments[1], arguments[2]); + case 65: + return Output(MOUSE_MIDDLE_MOVE, arguments[1], arguments[2]); + case 34: return Output(MOUSE_RIGHT_DOWN, arguments[1], arguments[2]); case 66: diff --git a/src/ftxui/component/terminal_input_parser.hpp b/src/ftxui/component/terminal_input_parser.hpp index 72fc095..db13d59 100644 --- a/src/ftxui/component/terminal_input_parser.hpp +++ b/src/ftxui/component/terminal_input_parser.hpp @@ -28,6 +28,8 @@ class TerminalInputParser { MOUSE_MOVE, MOUSE_LEFT_DOWN, MOUSE_LEFT_MOVE, + MOUSE_MIDDLE_DOWN, + MOUSE_MIDDLE_MOVE, MOUSE_RIGHT_DOWN, MOUSE_RIGHT_MOVE, };