refresh frequency set
This commit is contained in:
parent
124275f1a7
commit
14138f15e9
21
src/GUI.cpp
21
src/GUI.cpp
@ -12,19 +12,22 @@ auto GUI_run(int argc, char **argv) -> int {
|
|||||||
window_width = vkvm::getWidth();
|
window_width = vkvm::getWidth();
|
||||||
char *resolusion = get_resolusion(window_height, window_width);
|
char *resolusion = get_resolusion(window_height, window_width);
|
||||||
std::cout << resolusion << std::endl;
|
std::cout << resolusion << std::endl;
|
||||||
GUI_Window *window = new GUI_Window(window_width, window_height + 30, "example");
|
auto *window = new GUI_Window(window_width, window_height + 30, "example");
|
||||||
Statusbar *status[5];
|
Statusbar *status[5];
|
||||||
//Dummy-Values TBD
|
//Dummy-Values TBD
|
||||||
window->begin();
|
window->begin();
|
||||||
Image *image = new Image(0, 30, window_width, window_height);
|
auto *image = new Image(0, 30, window_width, window_height);
|
||||||
|
|
||||||
status[0] = new Statusbar(0, 0, 300, 30, resolusion);
|
status[0] = new Statusbar(0, 0, 300, 30, resolusion);
|
||||||
status[1] = new Statusbar(300, 0, 170, 30, "Event:");
|
status[1] = new Statusbar(300, 0, 170, 30, "Event:");
|
||||||
status[2] = new Statusbar(470, 0, 200, 30, "Mouse Position:");
|
status[2] = new Statusbar(470, 0, 200, 30, "Mouse Position:");
|
||||||
vkvm::registerEvent(vkvm::EventType::Redraw, [image](){
|
vkvm::registerEvent(vkvm::EventType::Redraw, [image]() {
|
||||||
redraw(image);
|
redraw(image);
|
||||||
});
|
});
|
||||||
Fl::repeat_timeout(0.5, get_new_image, image);
|
vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [image]() {
|
||||||
|
image->setDelay(vkvm::getTimerInterruptInterval());
|
||||||
|
});
|
||||||
|
Fl::repeat_timeout(image->getDelay(), get_new_image, image);
|
||||||
window->end();
|
window->end();
|
||||||
window->show(argc, argv);
|
window->show(argc, argv);
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
@ -42,20 +45,20 @@ char *get_resolusion(int window_height, int window_width) {
|
|||||||
return resolusion;
|
return resolusion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void redraw(Image* image){
|
void redraw(Image *image) {
|
||||||
image->getPixels();
|
image->getPixels();
|
||||||
sleep(0.05);
|
|
||||||
image->redraw();
|
image->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_new_image(void *pointer) {
|
void get_new_image(void *pointer) {
|
||||||
((Image *) pointer)->getPixels();
|
Image *image = ((Image *) pointer);
|
||||||
Fl::repeat_timeout(0.5, refresh_image, pointer);
|
image->getPixels();
|
||||||
|
Fl::repeat_timeout(image->getDelay(), refresh_image, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh_image(void *pointer) {
|
void refresh_image(void *pointer) {
|
||||||
((Image *) pointer)->redraw();
|
((Image *) pointer)->redraw();
|
||||||
Fl::repeat_timeout(0.5, get_new_image, pointer);
|
get_new_image(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
22
src/GUI.hpp
22
src/GUI.hpp
@ -1,7 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Fl/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <Fl/Fl_Box.H>
|
#include <FL/Fl_Box.H>
|
||||||
#include <Fl/Fl_Export.H>
|
#include <FL/Fl_Export.H>
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -20,12 +20,12 @@
|
|||||||
* @param button The button that was pushed last.
|
* @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{};
|
||||||
vkvm::KeyCode keyCode;
|
vkvm::KeyCode keyCode;
|
||||||
|
|
||||||
int handle(int e);
|
int handle(int e) override;
|
||||||
|
|
||||||
char *position_to_string(int x, int y);
|
static char *position_to_string(int x, int y);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GUI_Window(int x, int y, const char *l);
|
GUI_Window(int x, int y, const char *l);
|
||||||
@ -40,12 +40,18 @@ public:
|
|||||||
|
|
||||||
class Image : public Fl_Widget {
|
class Image : public Fl_Widget {
|
||||||
uchar *buf;
|
uchar *buf;
|
||||||
|
double delay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Image(int x, int y, int w, int h);
|
Image(int x, int y, int w, int h);
|
||||||
|
|
||||||
void draw();
|
void draw() override;
|
||||||
|
|
||||||
void getPixels();
|
void getPixels();
|
||||||
|
|
||||||
|
void setDelay(double delay);
|
||||||
|
|
||||||
|
double getDelay();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Statusbar
|
/** Statusbar
|
||||||
@ -53,7 +59,7 @@ public:
|
|||||||
* @param text: A pointer to a char-array, that can contain a text like a status or whatever you want.
|
* @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);
|
||||||
};
|
};
|
||||||
|
@ -80,7 +80,7 @@ auto GUI_Window::handle(int e) -> int {
|
|||||||
GUI_Window::GUI_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
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*{
|
auto GUI_Window::position_to_string(int x,int y)->char*{
|
||||||
char *str = new char[25];
|
auto *str = new char[25];
|
||||||
std::string str_temp;
|
std::string str_temp;
|
||||||
str = strcpy(str,"Mouse Position X:");
|
str = strcpy(str,"Mouse Position X:");
|
||||||
str_temp = std::to_string(x);
|
str_temp = std::to_string(x);
|
||||||
|
@ -10,10 +10,10 @@ auto Image::draw() -> void {
|
|||||||
fl_draw_image(buf, x(), y(), w(), h());
|
fl_draw_image(buf, x(), y(), w(), h());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Image::Image(int x, int y, int w, int h) :
|
Image::Image(int x, int y, int w, int h) :
|
||||||
Fl_Widget(x, y, w, h, 0) {
|
Fl_Widget(x, y, w, h, nullptr) {
|
||||||
buf = new uchar[w * h * 3];
|
buf = new uchar[w * h * 3];
|
||||||
|
delay = ((double)vkvm::getTimerInterruptInterval())/1000;
|
||||||
/*Just an example.*/
|
/*Just an example.*/
|
||||||
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++) {
|
||||||
@ -32,6 +32,12 @@ auto Image::getPixels() -> void {
|
|||||||
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
auto Image::getDelay() -> double {
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Image::setDelay(double delay) -> void {
|
||||||
|
this->delay = delay;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user