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) :
Fl_Widget(x, y, w, h, 0) {
buf = new uchar[w * h * 3];
/*Just an example.*/
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
buf[(j + (i * w)) * 3 + 1] = 0xff;
}
}
}
/*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();
}
}
};