#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. */ class Image : public Fl_Widget { uchar *buf; //Function to draw a bitmap void draw() { fl_draw_image(buf, x(), y(), w(), h()); } /** The constructor of the image class, get additional * @param x: The mouse-position on the x-axis. * @param y: The mouse-position on the y-axis: * @param w: The width of a single pixel, * @param h: The height of a single pixel. */ public: 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*/ void change_color() { 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(); } } } }; /*Functions to refresh the image.*/ void refresh_image(void *pointer) { ((Image *) pointer)->redraw(); Fl::repeat_timeout(0.5, refresh_image, pointer);//nach 0.5 sec refresh_image(pointer) anrufen. Here pointer ist wie ein Parameter } void change_color(void *pointer) { ((Image *) pointer)->change_color(); Fl::repeat_timeout(1, change_color, pointer); } void refresh_statusbar(void *pointer) { ((Statusbar **) pointer)[0]->refresh_label(); Fl::repeat_timeout(0.5, refresh_statusbar, pointer); } void change_status(void *pointer) { ((Statusbar **) pointer)[0]->change_text(); Fl::repeat_timeout(1, change_status, pointer); }