#include "GUI_Window.hpp" #include "Image.hpp" #include "Statusbar.hpp" #include "GUI.hpp" /** GUI_run * The GUI_run-function starts all functions needed for the GUI. */ int redrawInterval; int width; int height; static void redrawCallback(void * pointer); int GUI_run(int argc, char **argv) { vkvm::initialize(0); //vkvm::setLogLevel(vkvm::LogLevel::DEBUG); width = vkvm::getWidth(); height = vkvm::getHeight(); redrawInterval = vkvm::getRedrawInterval(); char * resolution = get_resolution(width, height); vkvm::log(vkvm::LogLevel::DEBUG, resolution); auto * window = new GUI_Window(width, height + 30, "vKVM GUI"); Statusbar *status[5]; window->begin(); auto *image = new Image(0, 30, width, height); status[0] = new Statusbar(0, 0, 200, 30, resolution); status[1] = new Statusbar(200, 0, 170, 30, "Event:"); status[2] = new Statusbar(400, 0, 170, 30, "Mouse Position:"); vkvm::registerEvent(vkvm::EventType::Redraw, [image]() { image->getPixels(); image->redraw(); }); vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image, window, status]() { int newRedrawInterval = vkvm::getRedrawInterval(); if(newRedrawInterval != redrawInterval) { if(redrawInterval == -1 && newRedrawInterval != -1) { vkvm::log(vkvm::LogLevel::DEBUG, "adding timeout"); Fl::add_timeout(1.0, redrawCallback, image); } if(newRedrawInterval == -1) { vkvm::log(vkvm::LogLevel::DEBUG, "removing timeout"); Fl::remove_timeout(redrawCallback); } redrawInterval = newRedrawInterval; } int newWidth = vkvm::getWidth(); int newHeight = vkvm::getHeight(); if(newWidth != width || newHeight != height) { width = newWidth; height = newHeight; window->size(width, height + 30); image->size(width, height); status[0]->label(get_resolution(width, height)); window->redraw(); } }); Fl::add_timeout(1.0, redrawCallback, image); window->end(); window->show(argc, argv); return Fl::run(); } static void redrawCallback(void * pointer) { auto *image = static_cast(pointer); image->getPixels(); image->redraw(); Fl::repeat_timeout(redrawInterval / 1000.0, redrawCallback, image); }