2019-11-14 15:09:43 +01:00
|
|
|
#include "GUI.hpp"
|
|
|
|
|
|
|
|
/** Image
|
|
|
|
* The Image-class draws the bitmap that it get from the Shared Memory.
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
|
2019-11-18 14:56:11 +01:00
|
|
|
//Function to draw a bitmap
|
|
|
|
auto Image::draw() -> void {
|
|
|
|
fl_draw_image(buf, x(), y(), w(), h());
|
|
|
|
}
|
2019-11-14 15:09:43 +01:00
|
|
|
|
2019-11-18 14:56:11 +01:00
|
|
|
Image::Image(int x, int y, int w, int h) :
|
2019-12-10 22:39:12 +01:00
|
|
|
Fl_Widget(x, y, w, h, nullptr) {
|
2019-11-18 14:56:11 +01:00
|
|
|
buf = new uchar[w * h * 3];
|
2019-12-10 22:39:12 +01:00
|
|
|
delay = ((double)vkvm::getTimerInterruptInterval())/1000;
|
2019-11-18 14:56:11 +01:00
|
|
|
/*Just an example.*/
|
|
|
|
for (int i = 0; i < h; i++) {
|
|
|
|
for (int j = 0; j < w; j++) {
|
|
|
|
buf[(j + (i * w)) * 3 + 1] = 0xff;
|
2019-11-14 15:09:43 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-18 14:56:11 +01:00
|
|
|
}
|
2019-11-14 15:09:43 +01:00
|
|
|
|
2019-11-18 14:56:11 +01:00
|
|
|
/*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/
|
|
|
|
auto Image::getPixels() -> void {
|
|
|
|
for (int i = 0; i < h(); i++) {
|
|
|
|
for (int j = 0; j < w(); j++) {
|
|
|
|
vkvm::Color c = vkvm::getPixel(j, i);
|
|
|
|
buf[(i * w() + j) * 3 + 0] = c.getRed();
|
|
|
|
buf[(i * w() + j) * 3 + 1] = c.getGreen();
|
|
|
|
buf[(i * w() + j) * 3 + 2] = c.getBlue();
|
2019-11-14 15:09:43 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-10 22:39:12 +01:00
|
|
|
}
|
2019-11-14 15:09:43 +01:00
|
|
|
|
2019-12-10 22:39:12 +01:00
|
|
|
auto Image::getDelay() -> double {
|
|
|
|
return delay;
|
|
|
|
}
|
2019-11-14 15:09:43 +01:00
|
|
|
|
2019-12-10 22:39:12 +01:00
|
|
|
auto Image::setDelay(double delay) -> void {
|
|
|
|
this->delay = delay;
|
|
|
|
}
|