121 lines
4.4 KiB
C++
121 lines
4.4 KiB
C++
#include "GUI_Window.hpp"
|
|
|
|
|
|
/*Function to handle the input*/
|
|
auto GUI_Window::handle(int e) -> int {
|
|
switch (e) {
|
|
/*Mousebutton*/
|
|
case FL_PUSH:
|
|
x = Fl::event_x();
|
|
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);
|
|
} 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);
|
|
} else {
|
|
mouse_status |= Mouse_Status::middle_down;
|
|
this->child(2)->label("Event:Mouse Middle Down");
|
|
vkvm::callEvent(vkvm::EventType::MouseMiddleDown);
|
|
}
|
|
return 1;
|
|
/*Mousebutton and movement*/
|
|
case FL_RELEASE:
|
|
x = Fl::event_x();
|
|
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);
|
|
} 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);
|
|
} else {
|
|
mouse_status &= Mouse_Status::middle_up;
|
|
this->child(2)->label("Event:Mouse Middle Up");
|
|
vkvm::callEvent(vkvm::EventType::MouseMiddleUp);
|
|
}
|
|
return 1;
|
|
case FL_DRAG:
|
|
x = Fl::event_x();
|
|
y = Fl::event_y();
|
|
vkvm::setMousePosition(x, y);
|
|
this->child(3)->label(position_to_string(x, y));
|
|
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:
|
|
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*/
|
|
case FL_KEYBOARD:
|
|
button = Fl::event_button();
|
|
keyCode = vkvm::KeyCode(button);
|
|
vkvm::buttonPressed(keyCode);
|
|
vkvm::callEvent(vkvm::EventType::KeyDown);
|
|
this->child(2)->label("Event:Key Down");
|
|
return 1;
|
|
case FL_KEYUP:
|
|
button = Fl::event_button();
|
|
keyCode = vkvm::KeyCode(button);
|
|
vkvm::buttonPressed(keyCode);
|
|
vkvm::callEvent(vkvm::EventType::KeyUp);
|
|
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 * {
|
|
auto *str = new char[25];
|
|
std::string str_temp;
|
|
str = strcpy(str, "Mouse Position X:");
|
|
str_temp = std::to_string(x);
|
|
str = strcat(str, str_temp.c_str());
|
|
str = strcat(str, " Y:");
|
|
str_temp = std::to_string(y);
|
|
str = strcat(str, str_temp.c_str());
|
|
return str;
|
|
}
|
|
|
|
|