fix green backgrund problem

fix mouse interrupt problem
This commit is contained in:
chenhuan 2019-12-12 13:05:20 +01:00
parent aa511a2315
commit 555f5a551d
3 changed files with 55 additions and 19 deletions

View File

@ -5,6 +5,7 @@
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#include <unistd.h> #include <unistd.h>
#include "Mouse_Status.hpp"
#include "vkvm.hpp" #include "vkvm.hpp"
#include "internal.hpp" #include "internal.hpp"
@ -20,7 +21,7 @@
* @param button The button that was pushed last. * @param button The button that was pushed last.
*/ */
class GUI_Window : public Fl_Window { class GUI_Window : public Fl_Window {
int x, y, button,lastX,lastY; int x, y, button,lastX,lastY,mouse_status;
vkvm::KeyCode keyCode; vkvm::KeyCode keyCode;
int handle(int e) override; int handle(int e) override;
@ -74,4 +75,5 @@ void redraw(Image *image);
int GUI_run(int argc, char **argv); int GUI_run(int argc, char **argv);
#endif //GUI_GUI_HPP #endif //GUI_GUI_HPP

View File

@ -10,14 +10,20 @@ auto GUI_Window::handle(int e) -> int {
y = Fl::event_y(); y = Fl::event_y();
vkvm::setMousePosition(x, y); vkvm::setMousePosition(x, y);
if (Fl::event_button() == FL_LEFT_MOUSE) { if (Fl::event_button() == FL_LEFT_MOUSE) {
mouse_status |= Mouse_Status::left_down;
this->child(2)->label("Event:Mouse Left Down"); this->child(2)->label("Event:Mouse Left Down");
vkvm::callEvent(vkvm::EventType::MouseLeftDown); vkvm::callEvent(vkvm::EventType::MouseLeftDown);
std::cout<<mouse_status<<std::endl;
} else if (Fl::event_button() == FL_RIGHT_MOUSE) { } else if (Fl::event_button() == FL_RIGHT_MOUSE) {
mouse_status |= Mouse_Status::right_down;
this->child(2)->label("Event:Mouse Right Down"); this->child(2)->label("Event:Mouse Right Down");
vkvm::callEvent(vkvm::EventType::MouseRightDown); vkvm::callEvent(vkvm::EventType::MouseRightDown);
std::cout<<mouse_status<<std::endl;
} else { } else {
mouse_status |= Mouse_Status::middle_down;
this->child(2)->label("Event:Mouse Middle Down"); this->child(2)->label("Event:Mouse Middle Down");
vkvm::callEvent(vkvm::EventType::MouseMiddleDown); vkvm::callEvent(vkvm::EventType::MouseMiddleDown);
std::cout<<mouse_status<<std::endl;
} }
return 1; return 1;
/*Mousebutton and movement*/ /*Mousebutton and movement*/
@ -26,14 +32,20 @@ auto GUI_Window::handle(int e) -> int {
y = Fl::event_y(); y = Fl::event_y();
vkvm::setMousePosition(x, y); vkvm::setMousePosition(x, y);
if (Fl::event_button() == FL_LEFT_MOUSE) { if (Fl::event_button() == FL_LEFT_MOUSE) {
mouse_status &= Mouse_Status::left_up;
this->child(2)->label("Event:Mouse Left Up"); this->child(2)->label("Event:Mouse Left Up");
vkvm::callEvent(vkvm::EventType::MouseLeftUp); vkvm::callEvent(vkvm::EventType::MouseLeftUp);
std::cout<<mouse_status<<std::endl;
} else if (Fl::event_button() == FL_RIGHT_MOUSE) { } else if (Fl::event_button() == FL_RIGHT_MOUSE) {
mouse_status &= Mouse_Status::right_up;
this->child(2)->label("Event:Mouse Right Up"); this->child(2)->label("Event:Mouse Right Up");
vkvm::callEvent(vkvm::EventType::MouseRightUp); vkvm::callEvent(vkvm::EventType::MouseRightUp);
std::cout<<mouse_status<<std::endl;
} else { } else {
mouse_status &= Mouse_Status::middle_up;
this->child(2)->label("Event:Mouse Middle Up"); this->child(2)->label("Event:Mouse Middle Up");
vkvm::callEvent(vkvm::EventType::MouseMiddleUp); vkvm::callEvent(vkvm::EventType::MouseMiddleUp);
std::cout<<mouse_status<<std::endl;
} }
return 1; return 1;
case FL_DRAG: case FL_DRAG:
@ -41,19 +53,24 @@ auto GUI_Window::handle(int e) -> int {
y = Fl::event_y(); y = Fl::event_y();
vkvm::setMousePosition(x, y); vkvm::setMousePosition(x, y);
this->child(3)->label(position_to_string(x, y)); this->child(3)->label(position_to_string(x, y));
if (Fl::event_button() == FL_LEFT_MOUSE) { switch (mouse_status) {
case Mouse_Status::left_down :
this->child(2)->label("Event:Mouse Left Drag"); this->child(2)->label("Event:Mouse Left Drag");
vkvm::callEvent(vkvm::EventType::MouseMove); vkvm::callEvent(vkvm::EventType::MouseMove);
} else if (Fl::event_button() == FL_RIGHT_MOUSE) { break;
case Mouse_Status::right_down :
this->child(2)->label("Event:Mouse Right Drag"); this->child(2)->label("Event:Mouse Right Drag");
vkvm::callEvent(vkvm::EventType::MouseMove); vkvm::callEvent(vkvm::EventType::MouseMove);
} else { break;
case Mouse_Status::middle_down :
this->child(2)->label("Event:Mouse Middle Drag"); this->child(2)->label("Event:Mouse Middle Drag");
vkvm::callEvent(vkvm::EventType::MouseMove); vkvm::callEvent(vkvm::EventType::MouseMove);
} }
return 1; return 1;
/*Mousemovement*/ /*Mousemovement*/
case FL_MOVE: case FL_MOVE:
if (mouse_status == 0) {
x = Fl::event_x(); x = Fl::event_x();
y = Fl::event_y(); y = Fl::event_y();
if (lastX != x || lastY != y) { if (lastX != x || lastY != y) {
@ -64,6 +81,9 @@ auto GUI_Window::handle(int e) -> int {
this->child(2)->label("Event:Mouse Move"); this->child(2)->label("Event:Mouse Move");
this->child(3)->label(position_to_string(x, y)); this->child(3)->label(position_to_string(x, y));
} }
} else {
handle(FL_DRAG);
}
return 1; return 1;
/*keyboardbutton*/ /*keyboardbutton*/
case FL_KEYBOARD: case FL_KEYBOARD:
@ -82,12 +102,14 @@ auto GUI_Window::handle(int e) -> int {
this->child(2)->label("Event:Key Up"); this->child(2)->label("Event:Key Up");
return 1; return 1;
} }
return -1; return -1;
} }
GUI_Window::GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) { GUI_Window::GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {
lastX = 0; lastX = 0;
lastY = 0; lastY = 0;
mouse_status = 0;
} }
auto GUI_Window::position_to_string(int x, int y) -> char * { auto GUI_Window::position_to_string(int x, int y) -> char * {

12
src/Mouse_Status.hpp Normal file
View File

@ -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,
};