76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
#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);
|
|
static void refreshCallback(void * pointer);
|
|
|
|
int GUI_run(int argc, char **argv) {
|
|
vkvm::initialize(0);
|
|
width = vkvm::getWidth();
|
|
height = vkvm::getHeight();
|
|
redrawInterval = vkvm::getRedrawInterval();
|
|
char *resolution = get_resolution(width, height);
|
|
std::cout << resolution << std::endl;
|
|
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, 300, 30, resolution);
|
|
status[1] = new Statusbar(300, 0, 170, 30, "Event:");
|
|
status[2] = new Statusbar(470, 0, 200, 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) {
|
|
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::repeat_timeout((double) redrawInterval / 1000, refreshCallback, image);
|
|
window->end();
|
|
window->show(argc, argv);
|
|
return Fl::run();
|
|
}
|
|
|
|
static void refreshCallback(void * pointer) {
|
|
auto *image = static_cast<Image*>(pointer);
|
|
image->getPixels();
|
|
|
|
Fl::repeat_timeout((double) redrawInterval / 1000, redrawCallback, image);
|
|
}
|
|
|
|
static void redrawCallback(void * pointer) {
|
|
auto *image = static_cast<Image*>(pointer);
|
|
image->redraw();
|
|
refreshCallback(image);
|
|
} |