2019-10-23 13:32:13 +02:00
|
|
|
|
2019-10-26 16:39:25 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <Fl/Fl.H>
|
2019-11-07 12:43:16 +01:00
|
|
|
#include <Fl/Fl_Box.H>
|
|
|
|
#include <Fl/Fl_Output.H>
|
2019-10-26 16:39:25 +02:00
|
|
|
#include <FL/Fl_Window.H>
|
2019-10-28 22:14:42 +01:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
2019-10-23 13:32:13 +02:00
|
|
|
|
2019-10-28 22:14:42 +01:00
|
|
|
#define window_height 600
|
|
|
|
#define window_width 800
|
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
//Statusbar**************************************/
|
|
|
|
|
|
|
|
/** The class inherits a char *text from the Fl_Box. It also shows the window-resolution and the mouse-position.
|
|
|
|
* @param text: A pointer to a char-array, that can contain a text like a status or whatever you want.
|
|
|
|
* @parameter x: The mouse-position on the x-axis.
|
|
|
|
* @parameter y: The mouse-position on the y-axis:
|
|
|
|
* @parameter w: The width of a single pixel,
|
|
|
|
* @parameter h: The height of a single pixel.
|
|
|
|
*/
|
|
|
|
class Statusbar: public Fl_Box {
|
|
|
|
char *text;
|
|
|
|
public:
|
|
|
|
/** The constructor of Statusbar has to get additional parameters.
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
Statusbar(int x, int y, int w, int h, char *text) :
|
|
|
|
Fl_Box(x, y, w, h,text) {
|
|
|
|
this->text = text;
|
|
|
|
};
|
|
|
|
void set_text(char *text) {
|
|
|
|
this->text = text;
|
|
|
|
}
|
|
|
|
//An exampel to show, how the content of the text can be changed.
|
|
|
|
void change_text(){
|
|
|
|
if(text=="status0")
|
|
|
|
set_text("status1");
|
|
|
|
else
|
|
|
|
set_text("status0");
|
|
|
|
}
|
|
|
|
//This function refreshes the statusbar
|
|
|
|
void refresh_label(){
|
|
|
|
this->label(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//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-10-28 22:14:42 +01:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
class Image : public Fl_Widget {
|
|
|
|
uchar *buf;
|
|
|
|
|
|
|
|
//Function to draw a bitmap
|
2019-11-06 12:17:23 +01:00
|
|
|
void draw() {
|
2019-11-07 12:43:16 +01:00
|
|
|
fl_draw_image(buf, x(), y(), w(), h());
|
2019-11-06 12:17:23 +01:00
|
|
|
}
|
2019-11-07 12:43:16 +01:00
|
|
|
/** 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.
|
|
|
|
*/
|
2019-11-06 12:17:23 +01:00
|
|
|
|
|
|
|
public:
|
2019-11-07 12:43:16 +01:00
|
|
|
/*Constructor*/
|
|
|
|
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. The colors are changing in this order: green, blue, red*/
|
|
|
|
void change_color() {
|
|
|
|
for (int j = 1; j < w() * h() * 3; j++) {
|
|
|
|
if (buf[j] == 0xff) {
|
|
|
|
buf[j] = 0;
|
|
|
|
buf[j - 1] = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buf[2] == 0xff)
|
|
|
|
buf[w() * h() * 3 - 1] = 0xff;
|
2019-11-06 12:17:23 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
//My_Window*************************************/
|
|
|
|
/** The My_Windows-class generates a window, within the window it recognizes the curretn mouse-position.
|
|
|
|
* It also recognizes if a button is pushed on the keyboard or the mouse. Furthermore the class depict the
|
|
|
|
* content of the Image-class and provides functions to refresh it.
|
|
|
|
* @parame x The mouse-position on the x-axis.
|
|
|
|
* @parame y The mouse-position on the y-axis.
|
|
|
|
* @parame button The button that was pushed last.
|
|
|
|
*/
|
2019-11-06 12:17:23 +01:00
|
|
|
class My_Window : public Fl_Window {
|
|
|
|
int x, y, button;
|
2019-11-07 12:43:16 +01:00
|
|
|
|
|
|
|
/*Function to handle the input*/
|
2019-11-06 12:17:23 +01:00
|
|
|
int handle(int e) {
|
|
|
|
switch (e) {
|
2019-11-07 12:43:16 +01:00
|
|
|
/*Mousebutton*/
|
2019-11-06 12:17:23 +01:00
|
|
|
case FL_PUSH:
|
2019-11-07 12:43:16 +01:00
|
|
|
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:left" << std::endl;
|
2019-11-07 12:43:16 +01:00
|
|
|
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:right" << std::endl;
|
2019-11-07 12:43:16 +01:00
|
|
|
} else {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:middle" << std::endl;
|
|
|
|
}
|
|
|
|
return 1;
|
2019-11-07 12:43:16 +01:00
|
|
|
/*Mousebutton and movement*/
|
2019-11-06 12:17:23 +01:00
|
|
|
case FL_DRAG:
|
|
|
|
x = Fl::event_x();
|
|
|
|
y = Fl::event_y();
|
|
|
|
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
2019-11-07 12:43:16 +01:00
|
|
|
if (Fl::event_button() == FL_LEFT_MOUSE) {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:left" << std::endl;
|
2019-11-07 12:43:16 +01:00
|
|
|
} else if (Fl::event_button() == FL_RIGHT_MOUSE) {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:right" << std::endl;
|
2019-11-07 12:43:16 +01:00
|
|
|
} else {
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Mouse:middle" << std::endl;
|
|
|
|
}
|
|
|
|
return 1;
|
2019-11-07 12:43:16 +01:00
|
|
|
/*Mousemovement*/
|
2019-10-26 16:39:25 +02:00
|
|
|
case FL_MOVE:
|
|
|
|
x = Fl::event_x();
|
|
|
|
y = Fl::event_y();
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
2019-10-26 16:39:25 +02:00
|
|
|
return 1;
|
2019-11-07 12:43:16 +01:00
|
|
|
/*keyboardbutton*/
|
2019-10-26 16:39:25 +02:00
|
|
|
case FL_KEYBOARD:
|
|
|
|
button = Fl::event_button();
|
2019-11-06 12:17:23 +01:00
|
|
|
std::cout << "Keyboard:" << (unsigned short) button << std::endl;
|
2019-10-26 16:39:25 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2019-10-28 22:14:42 +01:00
|
|
|
|
2019-10-26 16:39:25 +02:00
|
|
|
}
|
2019-10-28 22:14:42 +01:00
|
|
|
|
2019-10-26 16:39:25 +02:00
|
|
|
public:
|
2019-11-07 12:43:16 +01:00
|
|
|
/*Constructor*/
|
|
|
|
My_Window(int x, int y, const char *l) : Fl_Window(x, y, l) {}
|
2019-10-26 16:39:25 +02:00
|
|
|
};
|
2019-10-23 13:32:13 +02:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
/*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_bild(pointer) anrufen. Here pointer ist wie ein Parameter
|
2019-11-06 12:17:23 +01:00
|
|
|
}
|
2019-10-26 16:39:25 +02:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
void change_color(void *pointer) {
|
|
|
|
((Image *) pointer)->change_color();
|
|
|
|
Fl::repeat_timeout(1, change_color, pointer);
|
2019-11-06 12:17:23 +01:00
|
|
|
}
|
2019-10-26 16:39:25 +02:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
void refresh_statusbar(void *pointer) {
|
|
|
|
((Statusbar **) pointer)[0]->refresh_label();
|
|
|
|
Fl::repeat_timeout(0.5, refresh_statusbar, pointer);
|
|
|
|
}
|
2019-11-06 12:17:23 +01:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
void change_status(void *pointer) {
|
|
|
|
((Status_Leiste **) pointer)[0]->change_text();
|
|
|
|
Fl::repeat_timeout(1, change_status, pointer);
|
|
|
|
}
|
2019-11-06 12:17:23 +01:00
|
|
|
|
2019-11-07 12:43:16 +01:00
|
|
|
//main*************************************/
|
|
|
|
/**
|
|
|
|
* The main function initializes all needed classes and executes the functions.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
My_Window *window = new My_Window(window_width, window_height, "example");
|
|
|
|
Status_Leiste *status[5];
|
2019-10-26 16:39:25 +02:00
|
|
|
window->begin();
|
2019-11-07 12:43:16 +01:00
|
|
|
Bild *bild = new Bild(0, 30, window_width, window_height - 30);
|
|
|
|
status[0] = new Status_Leiste(0, 0, 60, 30, "status0");
|
|
|
|
status[1] = new Status_Leiste(60, 0, 60, 30, "status1");
|
|
|
|
status[2] = new Status_Leiste(120, 0, 60, 30, "status2");
|
|
|
|
status[3] = new Status_Leiste(180, 0, 60, 30, "status3");
|
|
|
|
status[4] = new Status_Leiste(240, 0, 60, 30, "status4");
|
|
|
|
Fl::repeat_timeout(0.5, refresh_bild, bild);
|
|
|
|
Fl::repeat_timeout(1, change_color, bild);
|
|
|
|
Fl::repeat_timeout(0.5, refresh_status_leiste, status);
|
|
|
|
Fl::repeat_timeout(1, change_status, status);
|
2019-10-26 16:39:25 +02:00
|
|
|
window->end();
|
2019-11-06 12:17:23 +01:00
|
|
|
window->show(argc, argv);
|
2019-10-26 16:39:25 +02:00
|
|
|
return Fl::run();
|
2019-11-07 12:43:16 +01:00
|
|
|
}main
|