fix green backgrund problem

This commit is contained in:
chenhuan 2019-12-12 00:02:59 +01:00
parent b1552db800
commit aa511a2315
4 changed files with 24 additions and 24 deletions

View File

@ -25,7 +25,7 @@ auto GUI_run(int argc, char **argv) -> int {
redraw(image); redraw(image);
}); });
vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image]() { vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image]() {
image->setDelay(vkvm::getRedrawInterval(); image->setDelay(vkvm::getRedrawInterval());
}); });
Fl::repeat_timeout(image->getDelay(), get_new_image, image); Fl::repeat_timeout(image->getDelay(), get_new_image, image);
window->end(); window->end();

View File

@ -20,7 +20,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{}; int x, y, button,lastX,lastY;
vkvm::KeyCode keyCode; vkvm::KeyCode keyCode;
int handle(int e) override; int handle(int e) override;

View File

@ -8,7 +8,7 @@ auto GUI_Window::handle(int e) -> int {
case FL_PUSH: case FL_PUSH:
x = Fl::event_x(); x = Fl::event_x();
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) {
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);
@ -24,7 +24,7 @@ auto GUI_Window::handle(int e) -> int {
case FL_RELEASE: case FL_RELEASE:
x = Fl::event_x(); x = Fl::event_x();
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) {
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);
@ -39,8 +39,8 @@ auto GUI_Window::handle(int e) -> int {
case FL_DRAG: case FL_DRAG:
x = Fl::event_x(); x = Fl::event_x();
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) { if (Fl::event_button() == FL_LEFT_MOUSE) {
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);
@ -51,16 +51,19 @@ auto GUI_Window::handle(int e) -> int {
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:
x = Fl::event_x(); x = Fl::event_x();
y = Fl::event_y(); y = Fl::event_y();
vkvm::setMousePosition(x,y); if (lastX != x || lastY != y) {
vkvm::callEvent(vkvm::EventType::MouseMove); lastX = x;
this->child(2)->label("Event:Mouse Move"); lastY = y;
this->child(3)->label(position_to_string(x,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; return 1;
/*keyboardbutton*/ /*keyboardbutton*/
case FL_KEYBOARD: case FL_KEYBOARD:
@ -72,7 +75,7 @@ auto GUI_Window::handle(int e) -> int {
return 1; return 1;
case FL_KEYUP: case FL_KEYUP:
button = Fl::event_button(); button = Fl::event_button();
std::cout<<button<<std::endl; std::cout << button << std::endl;
keyCode = vkvm::KeyCode(button); keyCode = vkvm::KeyCode(button);
vkvm::buttonPressed(keyCode); vkvm::buttonPressed(keyCode);
vkvm::callEvent(vkvm::EventType::KeyUp); vkvm::callEvent(vkvm::EventType::KeyUp);
@ -82,17 +85,20 @@ auto GUI_Window::handle(int e) -> int {
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;
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]; auto *str = new char[25];
std::string str_temp; std::string str_temp;
str = strcpy(str,"Mouse Position X:"); str = strcpy(str, "Mouse Position X:");
str_temp = std::to_string(x); str_temp = std::to_string(x);
str = strcat(str,str_temp.c_str()); str = strcat(str, str_temp.c_str());
str = strcat(str," Y:"); str = strcat(str, " Y:");
str_temp = std::to_string(y); str_temp = std::to_string(y);
str = strcat(str,str_temp.c_str()); str = strcat(str, str_temp.c_str());
return str; return str;
} }

View File

@ -14,12 +14,6 @@ Image::Image(int x, int y, int w, int h) :
Fl_Widget(x, y, w, h, nullptr) { Fl_Widget(x, y, w, h, nullptr) {
buf = new uchar[w * h * 3]; buf = new uchar[w * h * 3];
delay = ((double)vkvm::getRedrawInterval())/1000; 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*/ /*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/