diff --git a/src/GUI.cpp b/src/GUI.cpp index 1ea82d5..62386d2 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -1,7 +1,5 @@ #include "GUI.hpp" -#define window_height 600 -#define window_width 800 /** GUI_run * The GUI_run-function starts all functions needed for the GUI. @@ -9,34 +7,45 @@ auto GUI_run(int argc, char **argv) -> int { vkvm::initialize(0); - GUI_Window *window = new GUI_Window(window_width, window_height, "example"); + int window_height, window_width; + window_height = vkvm::getHeight(); + window_width = vkvm::getWidth(); + char *resolusion = get_resolusion(window_height, window_width); + std::cout << resolusion << std::endl; + GUI_Window *window = new GUI_Window(window_width, window_height + 30, "example"); Statusbar *status[5]; //Dummy-Values TBD window->begin(); - Image *image = new Image(0, 30, window_width, window_height - 30); - status[0] = new Statusbar(0, 0, 60, 30, "0"); - status[1] = new Statusbar(60, 0, 60, 30, "status1"); - status[2] = new Statusbar(120, 0, 60, 30, "status2"); - status[3] = new Statusbar(180, 0, 60, 30, "status3"); - status[4] = new Statusbar(240, 0, 60, 30, "status4"); + Image *image = new Image(0, 30, window_width, window_height); + status[0] = new Statusbar(0, 0, 300, 30, resolusion); + status[1] = new Statusbar(300, 0, 170, 30, "Event:"); + status[2] = new Statusbar(470, 0, 200, 30, "Mouse Position:"); Fl::repeat_timeout(0.5, refresh_image, image); - Fl::repeat_timeout(0.5, refresh_statusbar, status); window->end(); window->show(argc, argv); return Fl::run(); } +char *get_resolusion(int window_height, int window_width) { + char *resolusion = new char[25]; + std::string str_temp; + strcpy(resolusion, "Resolusion Height:"); + str_temp = std::to_string(window_height); + strcat(resolusion, str_temp.c_str()); + strcat(resolusion, " Width:"); + str_temp = std::to_string(window_height); + strcat(resolusion, str_temp.c_str()); + return resolusion; +} -void refresh_image(void *pointer) { +void get_new_image(void *pointer) { ((Image *) pointer)->getPixels(); - ((Image *) pointer)->redraw(); Fl::repeat_timeout(0.5, refresh_image, pointer); } - -void refresh_statusbar(void *pointer) { - ((Statusbar **) pointer)[0]->change_text(); - ((Statusbar **) pointer)[0]->refresh_label(); - Fl::repeat_timeout(0.5, refresh_statusbar, pointer); +void refresh_image(void *pointer) { + ((Image *) pointer)->redraw(); + Fl::repeat_timeout(0.5, get_new_image, pointer); } + diff --git a/src/GUI.hpp b/src/GUI.hpp index 502f001..010b0dd 100644 --- a/src/GUI.hpp +++ b/src/GUI.hpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "vkvm.hpp" @@ -21,7 +22,7 @@ class GUI_Window : public Fl_Window { int x, y, button; vkvm::KeyCode* keyCode; int handle(int e); - + char* position_to_string(int x,int y); public: GUI_Window(int x, int y, const char *l); }; @@ -51,18 +52,11 @@ class Statusbar : public Fl_Box { char *text; public: Statusbar(int x, int y, int w, int h, char *text); - - void set_text(char *text); - - void change_text(); - - void refresh_label(); }; +char* get_resolusion(int window_height, int window_width); void refresh_image(void *pointer); - -void refresh_statusbar(void *pointer); - +void get_new_image(void *pointer) ; int GUI_run(int argc, char **argv); #endif //GUI_GUI_HPP diff --git a/src/GUI_Window.cpp b/src/GUI_Window.cpp index 8f2cd69..dca0eb7 100644 --- a/src/GUI_Window.cpp +++ b/src/GUI_Window.cpp @@ -13,6 +13,7 @@ auto GUI_Window::handle(int e) -> int { } else { std::cout << "Mouse:middle" << std::endl; } + this->child(2)->label("Event:Mouse Button"); vkvm::callEvent(vkvm::EventType::MouseButton); return 1; /*Mousebutton and movement*/ @@ -27,6 +28,8 @@ auto GUI_Window::handle(int e) -> int { } else { std::cout << "Mouse:middle" << std::endl; } + this->child(2)->label("Event:Mouse Drag"); + this->child(3)->label(position_to_string(x,y)); vkvm::callEvent(vkvm::EventType::MouseButton); vkvm::callEvent(vkvm::EventType::MouseMove); return 1; @@ -36,6 +39,8 @@ auto GUI_Window::handle(int e) -> int { 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)); return 1; /*keyboardbutton*/ case FL_KEYBOARD: @@ -43,6 +48,7 @@ auto GUI_Window::handle(int e) -> int { keyCode = new 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(); @@ -50,11 +56,24 @@ auto GUI_Window::handle(int e) -> int { keyCode = new 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) {} +auto GUI_Window::position_to_string(int x,int y)->char*{ + char *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; +} + diff --git a/src/Statusbar.cpp b/src/Statusbar.cpp index 8e2e4a4..694d84a 100644 --- a/src/Statusbar.cpp +++ b/src/Statusbar.cpp @@ -12,20 +12,3 @@ Statusbar::Statusbar(int x, int y, int w, int h, char *text) : this->text = text; }; -auto Statusbar::set_text(char *text) -> void { - this->text = text; -} - -//An exampel to show, how the content of the text can be changed. -auto Statusbar::change_text() -> void { - if (text == "status0") - set_text("status1"); - else - set_text("status0"); -} - -//This function refreshes the statusbar. -auto Statusbar::refresh_label() -> void { - this->label(text); -} -