diff --git a/src/GUI.hpp b/src/GUI.hpp index 17cc0a8..7943393 100644 --- a/src/GUI.hpp +++ b/src/GUI.hpp @@ -5,6 +5,7 @@ #include #include #include +#include "Mouse_Status.hpp" #include "vkvm.hpp" #include "internal.hpp" @@ -20,7 +21,7 @@ * @param button The button that was pushed last. */ class GUI_Window : public Fl_Window { - int x, y, button,lastX,lastY; + int x, y, button,lastX,lastY,mouse_status; vkvm::KeyCode keyCode; int handle(int e) override; @@ -74,4 +75,5 @@ void redraw(Image *image); int GUI_run(int argc, char **argv); + #endif //GUI_GUI_HPP diff --git a/src/GUI_Window.cpp b/src/GUI_Window.cpp index 34c7948..c105c53 100644 --- a/src/GUI_Window.cpp +++ b/src/GUI_Window.cpp @@ -10,14 +10,20 @@ auto GUI_Window::handle(int e) -> int { y = Fl::event_y(); vkvm::setMousePosition(x, y); if (Fl::event_button() == FL_LEFT_MOUSE) { + mouse_status |= Mouse_Status::left_down; this->child(2)->label("Event:Mouse Left Down"); vkvm::callEvent(vkvm::EventType::MouseLeftDown); + std::cout<child(2)->label("Event:Mouse Right Down"); vkvm::callEvent(vkvm::EventType::MouseRightDown); + std::cout<child(2)->label("Event:Mouse Middle Down"); vkvm::callEvent(vkvm::EventType::MouseMiddleDown); + std::cout< int { y = Fl::event_y(); vkvm::setMousePosition(x, y); if (Fl::event_button() == FL_LEFT_MOUSE) { + mouse_status &= Mouse_Status::left_up; this->child(2)->label("Event:Mouse Left Up"); vkvm::callEvent(vkvm::EventType::MouseLeftUp); + std::cout<child(2)->label("Event:Mouse Right Up"); vkvm::callEvent(vkvm::EventType::MouseRightUp); + std::cout<child(2)->label("Event:Mouse Middle Up"); vkvm::callEvent(vkvm::EventType::MouseMiddleUp); + std::cout< int { y = Fl::event_y(); vkvm::setMousePosition(x, y); this->child(3)->label(position_to_string(x, y)); - if (Fl::event_button() == FL_LEFT_MOUSE) { - this->child(2)->label("Event:Mouse Left Drag"); - vkvm::callEvent(vkvm::EventType::MouseMove); - } else if (Fl::event_button() == FL_RIGHT_MOUSE) { - this->child(2)->label("Event:Mouse Right Drag"); - vkvm::callEvent(vkvm::EventType::MouseMove); - } else { - this->child(2)->label("Event:Mouse Middle Drag"); - vkvm::callEvent(vkvm::EventType::MouseMove); + switch (mouse_status) { + case Mouse_Status::left_down : + this->child(2)->label("Event:Mouse Left Drag"); + vkvm::callEvent(vkvm::EventType::MouseMove); + break; + case Mouse_Status::right_down : + this->child(2)->label("Event:Mouse Right Drag"); + vkvm::callEvent(vkvm::EventType::MouseMove); + break; + case Mouse_Status::middle_down : + this->child(2)->label("Event:Mouse Middle Drag"); + vkvm::callEvent(vkvm::EventType::MouseMove); } return 1; + /*Mousemovement*/ case FL_MOVE: - x = Fl::event_x(); - y = Fl::event_y(); - if (lastX != x || lastY != y) { - lastX = x; - lastY = y; - vkvm::setMousePosition(x, y); - vkvm::callEvent(vkvm::EventType::MouseMove); - this->child(2)->label("Event:Mouse Move"); - this->child(3)->label(position_to_string(x, y)); + if (mouse_status == 0) { + x = Fl::event_x(); + y = Fl::event_y(); + if (lastX != x || lastY != y) { + lastX = x; + lastY = y; + vkvm::setMousePosition(x, y); + vkvm::callEvent(vkvm::EventType::MouseMove); + this->child(2)->label("Event:Mouse Move"); + this->child(3)->label(position_to_string(x, y)); + } + } else { + handle(FL_DRAG); } return 1; /*keyboardbutton*/ @@ -82,12 +102,14 @@ auto GUI_Window::handle(int e) -> int { this->child(2)->label("Event:Key Up"); return 1; } + return -1; } GUI_Window::GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) { lastX = 0; lastY = 0; + mouse_status = 0; } auto GUI_Window::position_to_string(int x, int y) -> char * { diff --git a/src/Mouse_Status.hpp b/src/Mouse_Status.hpp new file mode 100644 index 0000000..9ebb122 --- /dev/null +++ b/src/Mouse_Status.hpp @@ -0,0 +1,12 @@ + + enum Mouse_Status { + left_down = 0b100, + right_down = 0b010, + middle_down = 0b001, + left_up = 0b011, + right_up = 0b101, + middle_up = 0b110, + }; + + +