1.code cleanup
2.mouse and keybroad interrupt
This commit is contained in:
parent
6d7d3c4d6d
commit
9ce74862a2
@ -22,7 +22,7 @@ file(GLOB_RECURSE TESTS test/*.cpp)
|
|||||||
set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library")
|
set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library")
|
||||||
|
|
||||||
include_directories(${LIB_PATH}/include)
|
include_directories(${LIB_PATH}/include)
|
||||||
add_executable(GUI ${SOURCES} ${HEADERS} main/main.cpp src/Statusbar.cpp src/GUI_Window.cpp src/Image.cpp src/GUI.hpp src/init.cpp)
|
add_executable(GUI ${SOURCES} ${HEADERS} main/main.cpp src/Statusbar.cpp src/GUI_Window.cpp src/Image.cpp src/GUI.hpp src/GUI.cpp)
|
||||||
|
|
||||||
target_link_libraries(GUI ${LIB_PATH}/lib/liblibrary.a)
|
target_link_libraries(GUI ${LIB_PATH}/lib/liblibrary.a)
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#include "GUI.hpp"
|
#include "../src/GUI.hpp"
|
||||||
|
|
||||||
/** main
|
/** main
|
||||||
* The main function executes the functions of the GUI.
|
* The main function executes the functions of the GUI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
GUI_init();
|
GUI_run(argc,argv);
|
||||||
GUI_run();
|
|
||||||
}
|
}
|
@ -1,35 +1,42 @@
|
|||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
|
|
||||||
#define window_height 600
|
#define window_height 600
|
||||||
#define window_width 800
|
#define window_width 800
|
||||||
/** GUI_init
|
|
||||||
* The GUI_init-function initializes all needed classes for the GUI.
|
|
||||||
*/
|
|
||||||
void GUI_init() {
|
|
||||||
vkvm::initialize(0);
|
|
||||||
My_Window *window = new My_Window(window_width, window_height, "example");
|
|
||||||
Statusbar *status[5];
|
|
||||||
Image *image = new Image(0, 30, window_width, window_height - 30);
|
|
||||||
|
|
||||||
//Dummy-Values TBD
|
|
||||||
status[0] = new Statusbar(0, 0, 60, 30, "status0");
|
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** GUI_run
|
/** GUI_run
|
||||||
* The GUI_run-function starts all functions needed for the GUI.
|
* The GUI_run-function starts all functions needed for the GUI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void GUI_run() {
|
auto GUI_run(int argc, char **argv) -> int {
|
||||||
|
vkvm::initialize(0);
|
||||||
|
GUI_Window *window = new GUI_Window(window_width, window_height, "example");
|
||||||
|
Statusbar *status[5];
|
||||||
|
//Dummy-Values TBD
|
||||||
window->begin();
|
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");
|
||||||
Fl::repeat_timeout(0.5, refresh_image, image);
|
Fl::repeat_timeout(0.5, refresh_image, image);
|
||||||
Fl::repeat_timeout(1, change_color, image);
|
|
||||||
Fl::repeat_timeout(0.5, refresh_statusbar, status);
|
Fl::repeat_timeout(0.5, refresh_statusbar, status);
|
||||||
Fl::repeat_timeout(1, change_status, status);
|
|
||||||
window->end();
|
window->end();
|
||||||
window->show(argc, argv);
|
window->show(argc, argv);
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void refresh_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);
|
||||||
|
}
|
||||||
|
|
55
src/GUI.hpp
55
src/GUI.hpp
@ -4,36 +4,65 @@
|
|||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
#include "vkvm.hpp"
|
#include "vkvm.hpp"
|
||||||
|
#include "internal.hpp"
|
||||||
|
|
||||||
#ifndef GUI_GUI_HPP
|
#ifndef GUI_GUI_HPP
|
||||||
#define 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 {
|
class GUI_Window : public Fl_Window {
|
||||||
int x, y, button;
|
int x, y, button;
|
||||||
|
|
||||||
int handle(int e);
|
int handle(int e);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l)
|
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 {
|
class Image : public Fl_Widget {
|
||||||
uchar *buf;
|
uchar *buf;
|
||||||
public:
|
public:
|
||||||
Image(int x, int y, int w, int h);
|
Image(int x, int y, int w, int h);
|
||||||
void refresh_image(void *pointer);
|
|
||||||
void change_color(void *pointer);
|
|
||||||
void refresh_statusbar(void *pointer);
|
|
||||||
void change_status(void *pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
void getPixels();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 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 {
|
class Statusbar : public Fl_Box {
|
||||||
char *text;
|
char *text;
|
||||||
public:
|
public:
|
||||||
Statusbar(int x, int y, int w, int h, char *text);
|
Statusbar(int x, int y, int w, int h, char *text);
|
||||||
void set_text(char *text);
|
|
||||||
void change_text();
|
|
||||||
void refresh_label();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GUI_init();
|
void set_text(char *text);
|
||||||
void GUI_run();
|
|
||||||
|
void change_text();
|
||||||
|
|
||||||
|
void refresh_label();
|
||||||
|
};
|
||||||
|
|
||||||
|
void refresh_image(void *pointer);
|
||||||
|
|
||||||
|
void refresh_statusbar(void *pointer);
|
||||||
|
|
||||||
|
int GUI_run(int argc, char **argv);
|
||||||
|
|
||||||
#endif //GUI_GUI_HPP
|
#endif //GUI_GUI_HPP
|
||||||
|
@ -1,22 +1,12 @@
|
|||||||
#include "GUI.hpp"
|
#include "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;
|
|
||||||
|
|
||||||
/*Function to handle the input*/
|
/*Function to handle the input*/
|
||||||
int handle(int e) {
|
auto GUI_Window::handle(int e) -> int {
|
||||||
switch (e) {
|
switch (e) {
|
||||||
/*Mousebutton*/
|
/*Mousebutton*/
|
||||||
case FL_PUSH:
|
case FL_PUSH:
|
||||||
|
vkvm::callEvent(vkvm::EventType::MouseButton);
|
||||||
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
||||||
std::cout << "Mouse:left" << std::endl;
|
std::cout << "Mouse:left" << std::endl;
|
||||||
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
||||||
@ -27,9 +17,11 @@ class GUI_Window : public Fl_Window {
|
|||||||
return 1;
|
return 1;
|
||||||
/*Mousebutton and movement*/
|
/*Mousebutton and movement*/
|
||||||
case FL_DRAG:
|
case FL_DRAG:
|
||||||
|
vkvm::callEvent(vkvm::EventType::MouseButton);
|
||||||
|
vkvm::callEvent(vkvm::EventType::MouseMove);
|
||||||
x = Fl::event_x();
|
x = Fl::event_x();
|
||||||
y = Fl::event_y();
|
y = Fl::event_y();
|
||||||
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
vkvm::setMousePosition(x,y);
|
||||||
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
||||||
std::cout << "Mouse:left" << std::endl;
|
std::cout << "Mouse:left" << std::endl;
|
||||||
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
||||||
@ -40,16 +32,19 @@ class GUI_Window : public Fl_Window {
|
|||||||
return 1;
|
return 1;
|
||||||
/*Mousemovement*/
|
/*Mousemovement*/
|
||||||
case FL_MOVE:
|
case FL_MOVE:
|
||||||
|
vkvm::callEvent(vkvm::EventType::MouseMove);
|
||||||
x = Fl::event_x();
|
x = Fl::event_x();
|
||||||
y = Fl::event_y();
|
y = Fl::event_y();
|
||||||
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
vkvm::setMousePosition(x,y);
|
||||||
return 1;
|
return 1;
|
||||||
/*keyboardbutton*/
|
/*keyboardbutton*/
|
||||||
case FL_KEYBOARD:
|
case FL_KEYBOARD:
|
||||||
|
vkvm::callEvent(vkvm::EventType::KeyDown);
|
||||||
button = Fl::event_button();
|
button = Fl::event_button();
|
||||||
std::cout << "Keyboard:" << (unsigned short) button << " down" << std::endl;
|
std::cout << "Keyboard:" << (unsigned short) button << " down" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
case FL_KEYUP:
|
case FL_KEYUP:
|
||||||
|
vkvm::callEvent(vkvm::EventType::KeyUp);
|
||||||
button = Fl::event_button();
|
button = Fl::event_button();
|
||||||
std::cout << "Keyboard:" << (unsigned short) button << " up" << std::endl;
|
std::cout << "Keyboard:" << (unsigned short) button << " up" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -57,7 +52,6 @@ class GUI_Window : public Fl_Window {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
GUI_Window::GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
||||||
GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@ -5,23 +5,13 @@
|
|||||||
* @param *buf: A pointer to the bitmap, that the image-class has to draw. Three chars are needed to get the RGB-value of a pixel, so the size equals window_height * window_width * 3.
|
* @param *buf: A pointer to the bitmap, that the image-class has to draw. Three chars are needed to get the RGB-value of a pixel, so the size equals window_height * window_width * 3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Image : public Fl_Widget {
|
|
||||||
uchar *buf;
|
|
||||||
//Function to draw a bitmap
|
//Function to draw a bitmap
|
||||||
void draw() {
|
auto Image::draw() -> void {
|
||||||
fl_draw_image(buf, x(), y(), w(), h());
|
fl_draw_image(buf, x(), y(), w(), 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public:
|
Image::Image(int x, int y, int w, int h) :
|
||||||
|
|
||||||
Image(int x, int y, int w, int h) :
|
|
||||||
Fl_Widget(x, y, w, h, 0) {
|
Fl_Widget(x, y, w, h, 0) {
|
||||||
buf = new uchar[w * h * 3];
|
buf = new uchar[w * h * 3];
|
||||||
/*Just an example.*/
|
/*Just an example.*/
|
||||||
@ -33,7 +23,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/
|
/*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/
|
||||||
void change_color() {
|
auto Image::getPixels() -> void {
|
||||||
for (int i = 0; i < h(); i++) {
|
for (int i = 0; i < h(); i++) {
|
||||||
for (int j = 0; j < w(); j++) {
|
for (int j = 0; j < w(); j++) {
|
||||||
vkvm::Color c = vkvm::getPixel(j, i);
|
vkvm::Color c = vkvm::getPixel(j, i);
|
||||||
@ -42,25 +32,6 @@ public:
|
|||||||
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
/*Functions to refresh the image.*/
|
|
||||||
void refresh_image(void *pointer) {
|
|
||||||
((Image *) pointer)->redraw();
|
|
||||||
Fl::repeat_timeout(0.5, refresh_image, pointer);//nach 0.5 sec refresh_image(pointer) anrufen. Here pointer ist wie ein Parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
void change_color(void *pointer) {
|
|
||||||
((Image *) pointer)->change_color();
|
|
||||||
Fl::repeat_timeout(1, change_color, pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh_statusbar(void *pointer) {
|
|
||||||
((Statusbar **) pointer)[0]->refresh_label();
|
|
||||||
Fl::repeat_timeout(0.5, refresh_statusbar, pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void change_status(void *pointer) {
|
|
||||||
((Statusbar **) pointer)[0]->change_text();
|
|
||||||
Fl::repeat_timeout(1, change_status, pointer);
|
|
||||||
}
|
|
||||||
|
@ -1,35 +1,31 @@
|
|||||||
#include "GUI.hpp"
|
#include "GUI.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 {
|
|
||||||
char *text;
|
|
||||||
public:
|
|
||||||
/** The constructor of Statusbar has to get additional parameters.
|
/** The constructor of Statusbar has to get additional parameters.
|
||||||
* @param x: The mouse-position on the x-axis.
|
* @param x: The mouse-position on the x-axis.
|
||||||
* @param y: The mouse-position on the y-axis:
|
* @param y: The mouse-position on the y-axis:
|
||||||
* @param w: The width of a single pixel,
|
* @param w: The width of a single pixel,
|
||||||
* @param h: The height of a single pixel.
|
* @param h: The height of a single pixel.
|
||||||
*/
|
*/
|
||||||
Statusbar (int x, int y, int w, int h, char *text) :
|
Statusbar::Statusbar(int x, int y, int w, int h, char *text) :
|
||||||
Fl_Box(x, y, w, h, text) {
|
Fl_Box(x, y, w, h, text) {
|
||||||
this->text = text;
|
this->text = text;
|
||||||
};
|
};
|
||||||
void set_text(char *text) {
|
|
||||||
|
auto Statusbar::set_text(char *text) -> void {
|
||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
//An exampel to show, how the content of the text can be changed.
|
//An exampel to show, how the content of the text can be changed.
|
||||||
void change_text(){
|
auto Statusbar::change_text() -> void {
|
||||||
if (text == "status0")
|
if (text == "status0")
|
||||||
set_text("status1");
|
set_text("status1");
|
||||||
else
|
else
|
||||||
set_text("status0");
|
set_text("status0");
|
||||||
}
|
}
|
||||||
|
|
||||||
//This function refreshes the statusbar.
|
//This function refreshes the statusbar.
|
||||||
void refresh_label(){
|
auto Statusbar::refresh_label() -> void {
|
||||||
this->label(text);
|
this->label(text);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user