diff --git a/src/GUI.cpp b/src/GUI.cpp index ccb838c..2cde0d1 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -25,7 +25,7 @@ auto GUI_run(int argc, char **argv) -> int { redraw(image); }); vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image]() { - image->setDelay(vkvm::getRedrawInterval(); + image->setDelay(vkvm::getRedrawInterval()); }); Fl::repeat_timeout(image->getDelay(), get_new_image, image); window->end(); diff --git a/src/GUI.hpp b/src/GUI.hpp index bd8c34d..17cc0a8 100644 --- a/src/GUI.hpp +++ b/src/GUI.hpp @@ -20,7 +20,7 @@ * @param button The button that was pushed last. */ class GUI_Window : public Fl_Window { - int x{}, y{}, button{}; + int x, y, button,lastX,lastY; vkvm::KeyCode keyCode; int handle(int e) override; diff --git a/src/GUI_Window.cpp b/src/GUI_Window.cpp index 50ec3d5..34c7948 100644 --- a/src/GUI_Window.cpp +++ b/src/GUI_Window.cpp @@ -8,7 +8,7 @@ auto GUI_Window::handle(int e) -> int { case FL_PUSH: x = Fl::event_x(); y = Fl::event_y(); - vkvm::setMousePosition(x,y); + vkvm::setMousePosition(x, y); if (Fl::event_button() == FL_LEFT_MOUSE) { this->child(2)->label("Event:Mouse Left Down"); vkvm::callEvent(vkvm::EventType::MouseLeftDown); @@ -24,7 +24,7 @@ auto GUI_Window::handle(int e) -> int { case FL_RELEASE: x = Fl::event_x(); y = Fl::event_y(); - vkvm::setMousePosition(x,y); + vkvm::setMousePosition(x, y); if (Fl::event_button() == FL_LEFT_MOUSE) { this->child(2)->label("Event:Mouse Left Up"); vkvm::callEvent(vkvm::EventType::MouseLeftUp); @@ -39,8 +39,8 @@ auto GUI_Window::handle(int e) -> int { case FL_DRAG: x = Fl::event_x(); y = Fl::event_y(); - vkvm::setMousePosition(x,y); - this->child(3)->label(position_to_string(x,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); @@ -51,16 +51,19 @@ auto GUI_Window::handle(int e) -> int { 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(); - 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 (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)); + } return 1; /*keyboardbutton*/ case FL_KEYBOARD: @@ -72,7 +75,7 @@ auto GUI_Window::handle(int e) -> int { return 1; case FL_KEYUP: button = Fl::event_button(); - std::cout< int { 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; + lastY = 0; +} -auto GUI_Window::position_to_string(int x,int y)->char*{ +auto GUI_Window::position_to_string(int x, int y) -> char * { auto *str = new char[25]; std::string str_temp; - str = strcpy(str,"Mouse Position X:"); + str = strcpy(str, "Mouse Position X:"); str_temp = std::to_string(x); - str = strcat(str,str_temp.c_str()); - str = strcat(str," Y:"); + str = strcat(str, str_temp.c_str()); + str = strcat(str, " Y:"); str_temp = std::to_string(y); - str = strcat(str,str_temp.c_str()); + str = strcat(str, str_temp.c_str()); return str; } diff --git a/src/Image.cpp b/src/Image.cpp index bee2edc..9ebee9f 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -14,12 +14,6 @@ Image::Image(int x, int y, int w, int h) : Fl_Widget(x, y, w, h, nullptr) { buf = new uchar[w * h * 3]; delay = ((double)vkvm::getRedrawInterval())/1000; - /*Just an example.*/ - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - buf[(j + (i * w)) * 3 + 1] = 0xff; - } - } } /*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/