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_draw.H>
#include <unistd.h>
#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

View File

@ -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<<mouse_status<<std::endl;
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
mouse_status |= Mouse_Status::right_down;
this->child(2)->label("Event:Mouse Right Down");
vkvm::callEvent(vkvm::EventType::MouseRightDown);
std::cout<<mouse_status<<std::endl;
} else {
mouse_status |= Mouse_Status::middle_down;
this->child(2)->label("Event:Mouse Middle Down");
vkvm::callEvent(vkvm::EventType::MouseMiddleDown);
std::cout<<mouse_status<<std::endl;
}
return 1;
/*Mousebutton and movement*/
@ -26,14 +32,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_up;
this->child(2)->label("Event:Mouse Left Up");
vkvm::callEvent(vkvm::EventType::MouseLeftUp);
std::cout<<mouse_status<<std::endl;
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
mouse_status &= Mouse_Status::right_up;
this->child(2)->label("Event:Mouse Right Up");
vkvm::callEvent(vkvm::EventType::MouseRightUp);
std::cout<<mouse_status<<std::endl;
} else {
mouse_status &= Mouse_Status::middle_up;
this->child(2)->label("Event:Mouse Middle Up");
vkvm::callEvent(vkvm::EventType::MouseMiddleUp);
std::cout<<mouse_status<<std::endl;
}
return 1;
case FL_DRAG:
@ -41,19 +53,24 @@ auto GUI_Window::handle(int e) -> 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) {
switch (mouse_status) {
case Mouse_Status::left_down :
this->child(2)->label("Event:Mouse Left Drag");
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");
vkvm::callEvent(vkvm::EventType::MouseMove);
} else {
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:
if (mouse_status == 0) {
x = Fl::event_x();
y = Fl::event_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(3)->label(position_to_string(x, y));
}
} else {
handle(FL_DRAG);
}
return 1;
/*keyboardbutton*/
case FL_KEYBOARD:
@ -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 * {

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