refresh frequency set
This commit is contained in:
parent
124275f1a7
commit
14138f15e9
17
src/GUI.cpp
17
src/GUI.cpp
@ -12,11 +12,11 @@ auto GUI_run(int argc, char **argv) -> int {
|
||||
window_width = vkvm::getWidth();
|
||||
char *resolusion = get_resolusion(window_height, window_width);
|
||||
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];
|
||||
//Dummy-Values TBD
|
||||
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[1] = new Statusbar(300, 0, 170, 30, "Event:");
|
||||
@ -24,7 +24,10 @@ auto GUI_run(int argc, char **argv) -> int {
|
||||
vkvm::registerEvent(vkvm::EventType::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->show(argc, argv);
|
||||
return Fl::run();
|
||||
@ -44,18 +47,18 @@ char *get_resolusion(int window_height, int window_width) {
|
||||
|
||||
void redraw(Image *image) {
|
||||
image->getPixels();
|
||||
sleep(0.05);
|
||||
image->redraw();
|
||||
}
|
||||
|
||||
void get_new_image(void *pointer) {
|
||||
((Image *) pointer)->getPixels();
|
||||
Fl::repeat_timeout(0.5, refresh_image, pointer);
|
||||
Image *image = ((Image *) pointer);
|
||||
image->getPixels();
|
||||
Fl::repeat_timeout(image->getDelay(), refresh_image, pointer);
|
||||
}
|
||||
|
||||
void refresh_image(void *pointer) {
|
||||
((Image *) pointer)->redraw();
|
||||
Fl::repeat_timeout(0.5, get_new_image, pointer);
|
||||
get_new_image(pointer);
|
||||
}
|
||||
|
||||
|
||||
|
20
src/GUI.hpp
20
src/GUI.hpp
@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <Fl/Fl.H>
|
||||
#include <Fl/Fl_Box.H>
|
||||
#include <Fl/Fl_Export.H>
|
||||
#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>
|
||||
@ -20,12 +20,12 @@
|
||||
* @param button The button that was pushed last.
|
||||
*/
|
||||
class GUI_Window : public Fl_Window {
|
||||
int x, y, button;
|
||||
int x{}, y{}, button{};
|
||||
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:
|
||||
GUI_Window(int x, int y, const char *l);
|
||||
@ -40,12 +40,18 @@ public:
|
||||
|
||||
class Image : public Fl_Widget {
|
||||
uchar *buf;
|
||||
double delay;
|
||||
|
||||
public:
|
||||
Image(int x, int y, int w, int h);
|
||||
|
||||
void draw();
|
||||
void draw() override;
|
||||
|
||||
void getPixels();
|
||||
|
||||
void setDelay(double delay);
|
||||
|
||||
double getDelay();
|
||||
};
|
||||
|
||||
/** Statusbar
|
||||
|
@ -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) {}
|
||||
|
||||
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;
|
||||
str = strcpy(str,"Mouse Position X:");
|
||||
str_temp = std::to_string(x);
|
||||
|
@ -10,10 +10,10 @@ auto Image::draw() -> void {
|
||||
fl_draw_image(buf, x(), y(), w(), 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];
|
||||
delay = ((double)vkvm::getTimerInterruptInterval())/1000;
|
||||
/*Just an example.*/
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
@ -32,6 +32,12 @@ 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user