GUI/src/Image.cpp

38 lines
1.1 KiB
C++
Raw Normal View History

#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.
*/
//Function to draw a bitmap
auto Image::draw() -> void {
fl_draw_image(buf, x(), y(), w(), h());
}
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) {
buf = new uchar[w * h * 3];
2019-12-10 22:42:07 +01:00
delay = ((double)vkvm::getRedrawInterval())/1000;
}
/*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-12-10 22:39:12 +01:00
}
2019-12-10 22:39:12 +01:00
auto Image::getDelay() -> double {
return delay;
}
2019-12-10 22:39:12 +01:00
auto Image::setDelay(double delay) -> void {
this->delay = delay;
}