Merge branch 'dev' into 'master'
Final Merge See merge request link/projekte/ws19/vkvm-new/gui!4
This commit is contained in:
commit
9b46130eb7
|
@ -31,7 +31,7 @@ make_test:
|
|||
- docker-ci
|
||||
script:
|
||||
- apt-get update
|
||||
- apt-get install -y g++ make cmake clang-tidy libfltk1.3 libfltk1.3-dev
|
||||
- apt-get install -y clang make cmake clang-tidy libfltk1.3 libfltk1.3-dev
|
||||
- mkdir current
|
||||
- ls | grep -v current | xargs mv -t current
|
||||
- git clone https://github.com/catchorg/Catch2.git
|
||||
|
@ -57,7 +57,7 @@ cmake_build:
|
|||
- docker-ci
|
||||
script:
|
||||
- apt-get update
|
||||
- apt-get install -y g++ make cmake clang-tidy libfltk1.3 libfltk1.3-dev
|
||||
- apt-get install -y clang make cmake clang-tidy libfltk1.3 libfltk1.3-dev
|
||||
- mkdir current
|
||||
- ls | grep -v current | xargs mv -t current
|
||||
- git clone https://github.com/catchorg/Catch2.git
|
||||
|
|
|
@ -8,6 +8,8 @@ if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
|
|||
endif()
|
||||
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "lib" "include")
|
||||
|
||||
set(CMAKE_C_COMPILER "clang")
|
||||
set(CMAKE_CXX_COMPILER "clang++")
|
||||
|
||||
project(GUI)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
|
106
src/GUI.cpp
106
src/GUI.cpp
|
@ -1,3 +1,6 @@
|
|||
#include "GUI_Window.hpp"
|
||||
#include "Image.hpp"
|
||||
#include "Statusbar.hpp"
|
||||
#include "GUI.hpp"
|
||||
|
||||
|
||||
|
@ -5,60 +8,73 @@
|
|||
* The GUI_run-function starts all functions needed for the GUI.
|
||||
*/
|
||||
|
||||
auto GUI_run(int argc, char **argv) -> int {
|
||||
vkvm::initialize(0);
|
||||
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;
|
||||
auto *window = new GUI_Window(window_width, window_height + 30, "example");
|
||||
Statusbar *status[5];
|
||||
//Dummy-Values TBD
|
||||
window->begin();
|
||||
auto *image = new Image(0, 30, window_width, window_height);
|
||||
int redrawInterval;
|
||||
int width;
|
||||
int 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:");
|
||||
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]() {
|
||||
redraw(image);
|
||||
image->getPixels();
|
||||
image->redraw();
|
||||
});
|
||||
vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image]() {
|
||||
image->setDelay(vkvm::getRedrawInterval());
|
||||
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::repeat_timeout(image->getDelay(), get_new_image, image);
|
||||
|
||||
Fl::add_timeout(1.0, redrawCallback, image);
|
||||
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, "Resolution Height:");
|
||||
str_temp = std::to_string(window_height);
|
||||
strcat(resolusion, str_temp.c_str());
|
||||
strcat(resolusion, " Width:");
|
||||
str_temp = std::to_string(window_width);
|
||||
strcat(resolusion, str_temp.c_str());
|
||||
return resolusion;
|
||||
}
|
||||
|
||||
void redraw(Image *image) {
|
||||
static void redrawCallback(void * pointer) {
|
||||
auto *image = static_cast<Image*>(pointer);
|
||||
image->getPixels();
|
||||
|
||||
image->redraw();
|
||||
}
|
||||
|
||||
void get_new_image(void *pointer) {
|
||||
Image *image = ((Image *) pointer);
|
||||
image->getPixels();
|
||||
Fl::repeat_timeout(image->getDelay(), refresh_image, pointer);
|
||||
}
|
||||
|
||||
void refresh_image(void *pointer) {
|
||||
((Image *) pointer)->redraw();
|
||||
get_new_image(pointer);
|
||||
}
|
||||
|
||||
Fl::repeat_timeout(redrawInterval / 1000.0, redrawCallback, image);
|
||||
|
||||
}
|
73
src/GUI.hpp
73
src/GUI.hpp
|
@ -1,79 +1,8 @@
|
|||
#include <iostream>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Box.H>
|
||||
#include <FL/Fl_Export.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/fl_draw.H>
|
||||
#include <unistd.h>
|
||||
#include "Mouse_Status.hpp"
|
||||
#include "vkvm.hpp"
|
||||
#include "internal.hpp"
|
||||
|
||||
#ifndef GUI_GUI_HPP
|
||||
#define GUI_GUI_HPP
|
||||
|
||||
/** GUI_Window
|
||||
* The GUI_Window-class generates a window, within the window it recognizes the curretn mouse-position.
|
||||
* It also recognizes if a button is pushed on the keyboard or the mouse. Furthermore the class depict the
|
||||
* content of the Image-class and provides functions to refresh it.
|
||||
* @param x The mouse-position on the x-axis.
|
||||
* @param y The mouse-position on the y-axis.
|
||||
* @param button The button that was pushed last.
|
||||
*/
|
||||
class GUI_Window : public Fl_Window {
|
||||
int x, y, button,lastX,lastY,mouse_status;
|
||||
vkvm::KeyCode keyCode;
|
||||
|
||||
int handle(int e) override;
|
||||
|
||||
static char *position_to_string(int x, int y);
|
||||
|
||||
public:
|
||||
GUI_Window(int x, int y, const char *l);
|
||||
};
|
||||
|
||||
/** The constructor of the image class, get additional
|
||||
* @param x: The mouse-position on the x-axis.
|
||||
* @param y: The mouse-position on the y-axis:
|
||||
* @param w: The width of a single pixel,
|
||||
* @param h: The height of a single pixel.
|
||||
*/
|
||||
|
||||
class Image : public Fl_Widget {
|
||||
uchar *buf;
|
||||
double delay;
|
||||
|
||||
public:
|
||||
Image(int x, int y, int w, int h);
|
||||
|
||||
void draw() override;
|
||||
|
||||
void getPixels();
|
||||
|
||||
void setDelay(double delay);
|
||||
|
||||
double getDelay();
|
||||
};
|
||||
|
||||
/** Statusbar
|
||||
* The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position.
|
||||
* @param text: A pointer to a char-array, that can contain a text like a status or whatever you want.
|
||||
*/
|
||||
class Statusbar : public Fl_Box {
|
||||
char* text;
|
||||
public:
|
||||
Statusbar(int x, int y, int w, int h, char *text);
|
||||
};
|
||||
|
||||
char *get_resolusion(int window_height, int window_width);
|
||||
|
||||
void refresh_image(void *pointer);
|
||||
|
||||
void get_new_image(void *pointer);
|
||||
|
||||
void redraw(Image *image);
|
||||
|
||||
int GUI_run(int argc, char **argv);
|
||||
|
||||
|
||||
#endif //GUI_GUI_HPP
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "GUI.hpp"
|
||||
#include "GUI_Window.hpp"
|
||||
|
||||
|
||||
/*Function to handle the input*/
|
||||
|
@ -13,17 +13,14 @@ auto GUI_Window::handle(int e) -> int {
|
|||
mouse_status |= Mouse_Status::left_down;
|
||||
this->child(2)->label("Event:Mouse Left Down");
|
||||
vkvm::callEvent(vkvm::EventType::MouseLeftDown);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
} 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);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
} else {
|
||||
mouse_status |= Mouse_Status::middle_down;
|
||||
this->child(2)->label("Event:Mouse Middle Down");
|
||||
vkvm::callEvent(vkvm::EventType::MouseMiddleDown);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
}
|
||||
return 1;
|
||||
/*Mousebutton and movement*/
|
||||
|
@ -35,17 +32,14 @@ auto GUI_Window::handle(int e) -> int {
|
|||
mouse_status &= Mouse_Status::left_up;
|
||||
this->child(2)->label("Event:Mouse Left Up");
|
||||
vkvm::callEvent(vkvm::EventType::MouseLeftUp);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
} 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);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
} else {
|
||||
mouse_status &= Mouse_Status::middle_up;
|
||||
this->child(2)->label("Event:Mouse Middle Up");
|
||||
vkvm::callEvent(vkvm::EventType::MouseMiddleUp);
|
||||
// std::cout<<mouse_status<<std::endl;
|
||||
}
|
||||
return 1;
|
||||
case FL_DRAG:
|
||||
|
@ -95,7 +89,6 @@ auto GUI_Window::handle(int e) -> int {
|
|||
return 1;
|
||||
case FL_KEYUP:
|
||||
button = Fl::event_button();
|
||||
std::cout << button << std::endl;
|
||||
keyCode = vkvm::KeyCode(button);
|
||||
vkvm::buttonPressed(keyCode);
|
||||
vkvm::callEvent(vkvm::EventType::KeyUp);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include <iostream>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/Fl_Box.H>
|
||||
#include <FL/Fl_Export.H>
|
||||
#include <FL/Fl_Window.H>
|
||||
#include <FL/fl_draw.H>
|
||||
#include <unistd.h>
|
||||
#include "Mouse_Status.hpp"
|
||||
#include "vkvm.hpp"
|
||||
#include "internal.hpp"
|
||||
#include "Image.hpp"
|
||||
|
||||
#ifndef GUI_GUI_HPP
|
||||
#define GUI_GUI_HPP
|
||||
|
||||
/** GUI_Window
|
||||
* The GUI_Window-class generates a window, within the window it recognizes the curretn mouse-position.
|
||||
* It also recognizes if a button is pushed on the keyboard or the mouse. Furthermore the class depict the
|
||||
* content of the Image-class and provides functions to refresh it.
|
||||
* @param x The mouse-position on the x-axis.
|
||||
* @param y The mouse-position on the y-axis.
|
||||
* @param button The button that was pushed last.
|
||||
*/
|
||||
class GUI_Window : public Fl_Window {
|
||||
int x, y, button,lastX,lastY,mouse_status;
|
||||
vkvm::KeyCode keyCode;
|
||||
|
||||
int handle(int e) override;
|
||||
|
||||
static char *position_to_string(int x, int y);
|
||||
|
||||
public:
|
||||
GUI_Window(int x, int y, const char *l);
|
||||
};
|
||||
#endif //GUI_GUI_HPP
|
|
@ -1,4 +1,6 @@
|
|||
#include "GUI.hpp"
|
||||
#include <FL/fl_draw.H>
|
||||
#include <vkvm.hpp>
|
||||
#include "Image.hpp"
|
||||
|
||||
/** Image
|
||||
* The Image-class draws the bitmap that it get from the Shared Memory.
|
||||
|
@ -13,7 +15,6 @@ auto Image::draw() -> void {
|
|||
Image::Image(int x, int y, int w, int h) :
|
||||
Fl_Widget(x, y, w, h, nullptr) {
|
||||
buf = new uchar[w * h * 3];
|
||||
delay = ((double)vkvm::getRedrawInterval())/1000;
|
||||
}
|
||||
|
||||
/*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/
|
||||
|
@ -26,12 +27,4 @@ auto Image::getPixels() -> void {
|
|||
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto Image::getDelay() -> double {
|
||||
return delay;
|
||||
}
|
||||
|
||||
auto Image::setDelay(double delay) -> void {
|
||||
this->delay = delay;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef GUI_IMAGE_HPP
|
||||
#define GUI_IMAGE_HPP
|
||||
|
||||
|
||||
#include <FL/fl_types.h>
|
||||
#include <FL/Fl_Widget.H>
|
||||
|
||||
/** The constructor of the image class, get additional
|
||||
* @param x: The mouse-position on the x-axis.
|
||||
* @param y: The mouse-position on the y-axis:
|
||||
* @param w: The width of a single pixel,
|
||||
* @param h: The height of a single pixel.
|
||||
*/
|
||||
|
||||
class Image : public Fl_Widget {
|
||||
uchar *buf;
|
||||
|
||||
public:
|
||||
Image(int x, int y, int w, int h);
|
||||
|
||||
void draw() override;
|
||||
|
||||
void getPixels();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include "GUI.hpp"
|
||||
#include "GUI_Window.hpp"
|
||||
#include "Statusbar.hpp"
|
||||
|
||||
|
||||
/** The constructor of Statusbar has to get additional parameters.
|
||||
|
@ -7,8 +8,18 @@
|
|||
* @param w: The width of a single pixel,
|
||||
* @param h: The height of a single pixel.
|
||||
*/
|
||||
Statusbar::Statusbar(int x, int y, int w, int h, char *text) :
|
||||
Fl_Box(x, y, w, h, text) {
|
||||
this->text = text;
|
||||
};
|
||||
Statusbar::Statusbar(int x, int y, int w, int h, char *text) : Fl_Box(x, y, w, h, text) {
|
||||
}
|
||||
|
||||
|
||||
char *get_resolution(int window_width, int window_height) {
|
||||
char *resolution = new char[25];
|
||||
std::string str_temp;
|
||||
strcpy(resolution, "Resolution:");
|
||||
str_temp = std::to_string(window_width);
|
||||
strcat(resolution, str_temp.c_str());
|
||||
strcat(resolution, " x ");
|
||||
str_temp = std::to_string(window_height);
|
||||
strcat(resolution, str_temp.c_str());
|
||||
return resolution;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by joethei on 08.01.20.
|
||||
//
|
||||
|
||||
#ifndef GUI_STATUSBAR_HPP
|
||||
#define GUI_STATUSBAR_HPP
|
||||
|
||||
/** Statusbar
|
||||
* The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position.
|
||||
* @param text: A pointer to a char-array, that can contain a text like a status or whatever you want.
|
||||
*/
|
||||
class Statusbar : public Fl_Box {
|
||||
public:
|
||||
Statusbar(int x, int y, int w, int h, char *text);
|
||||
};
|
||||
|
||||
char *get_resolution(int window_width, int window_height);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#include <catch2/catch.hpp>
|
||||
#include "../src/GUI.hpp"
|
||||
#include "../src/GUI_Window.hpp"
|
||||
|
||||
TEST_CASE("GUI Test") {
|
||||
REQUIRE(42 == 42);
|
||||
|
|
Loading…
Reference in New Issue