2019-10-23 13:32:13 +02:00
|
|
|
|
2019-10-26 16:39:25 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <Fl/Fl.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
2019-11-06 12:17:23 +01:00
|
|
|
#include <FL/Fl_Timer.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-06 12:17:23 +01:00
|
|
|
/**************************************[[l***************************************/
|
2019-10-26 16:39:25 +02:00
|
|
|
/* This class provides a view to copy the offscreen surface to */
|
2019-10-28 22:14:42 +01:00
|
|
|
|
2019-11-06 12:17:23 +01:00
|
|
|
//Pixel ist ein neue Class fuer ein Pixel
|
|
|
|
class Pixel : public Fl_Widget {
|
|
|
|
Fl_Color color;
|
|
|
|
//Pixel zu malen, x,y sind fuer die Postion in Window.w,h ist width und height.color ist die Farbe von Pixel
|
|
|
|
void draw() {
|
|
|
|
fl_draw_box(FL_FLAT_BOX, x(), y(), w(), h(), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
//Konstruktor
|
|
|
|
Pixel(int x, int y, int w, int h) :
|
|
|
|
Fl_Widget(x, y, w, h, 0) {}
|
|
|
|
//die Farbe von Pixel einstellen
|
|
|
|
void set_color(int RGB){
|
|
|
|
this->color = fl_rgb_color((uchar) ((RGB & 0xff000000) >> 24), (uchar) ((RGB & 0xff0000) >> 16),
|
|
|
|
(uchar) ((RGB & 0xff00) >> 8));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-26 16:39:25 +02:00
|
|
|
|
2019-11-06 12:17:23 +01:00
|
|
|
class My_Window : public Fl_Window {
|
|
|
|
int x, y, button;
|
|
|
|
int (*color_map)[window_width][window_height];
|
|
|
|
Pixel* pixels[window_width][window_height];
|
|
|
|
int c=0xff000000;
|
|
|
|
//die Inputs von Maus und Tastatur behandln
|
|
|
|
int handle(int e) {
|
|
|
|
switch (e) {
|
|
|
|
//Druck vom Maus behandln
|
|
|
|
case FL_PUSH:
|
|
|
|
if(Fl::event_button()==FL_LEFT_MOUSE){
|
|
|
|
std::cout << "Mouse:left" << std::endl;
|
|
|
|
}else if(Fl::event_button()==FL_RIGHT_MOUSE){
|
|
|
|
std::cout << "Mouse:right" << std::endl;
|
|
|
|
}else{
|
|
|
|
std::cout << "Mouse:middle" << std::endl;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
//Druck und Bewegung vom Maus behandln
|
|
|
|
case FL_DRAG:
|
|
|
|
x = Fl::event_x();
|
|
|
|
y = Fl::event_y();
|
|
|
|
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
|
|
|
if(Fl::event_button()==FL_LEFT_MOUSE){
|
|
|
|
std::cout << "Mouse:left" << std::endl;
|
|
|
|
}else if(Fl::event_button()==FL_RIGHT_MOUSE){
|
|
|
|
std::cout << "Mouse:right" << std::endl;
|
|
|
|
}else{
|
|
|
|
std::cout << "Mouse:middle" << std::endl;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
//Bewegung vom Maus behandln
|
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-06 12:17:23 +01:00
|
|
|
//Druck von der Tastator behandln
|
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-11-06 12:17:23 +01:00
|
|
|
// case FL_:
|
2019-10-26 16:39:25 +02:00
|
|
|
}
|
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-06 12:17:23 +01:00
|
|
|
//Konstruktor
|
|
|
|
My_Window(int x, int y, const char *l, int (*color_map)[window_width][window_height]) : Fl_Window(x, y, l) {
|
|
|
|
this->color_map = color_map;
|
|
|
|
for (int i = 0; i < window_width; i++) {
|
|
|
|
for (int j = 0; j < window_height; j++) {
|
|
|
|
pixels[i][j]=new Pixel(i,j,1,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Window akualisieren, refresh
|
|
|
|
int draw_bild() {
|
|
|
|
for (int i = 0; i < window_width; i++) {
|
|
|
|
for (int j = 0; j < window_height; j++) {
|
|
|
|
pixels[i][j]->set_color((*color_map)[i][j]);
|
|
|
|
pixels[i][j]->redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-26 16:39:25 +02:00
|
|
|
};
|
2019-10-23 13:32:13 +02:00
|
|
|
|
2019-11-06 12:17:23 +01:00
|
|
|
//draw_bild() wird regelmaessig anrufen
|
|
|
|
void refresh(void* pointer){
|
|
|
|
((My_Window*)pointer)->draw_bild();
|
|
|
|
Fl::repeat_timeout(0.5, refresh,pointer);
|
|
|
|
}
|
|
|
|
//die Farbe von Pixels regekmaessig aendern
|
|
|
|
void change_color(void* pointer){
|
|
|
|
int (*color_map)[window_width][window_height];
|
|
|
|
color_map = (typeof(color_map))(pointer);
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int j = 0; j < 100; j++) {
|
|
|
|
(*color_map)[i][j] ^= 0xffff0000;
|
|
|
|
}
|
2019-10-28 22:14:42 +01:00
|
|
|
}
|
2019-10-26 16:39:25 +02:00
|
|
|
|
2019-11-06 12:17:23 +01:00
|
|
|
Fl::repeat_timeout(1, change_color,pointer);
|
|
|
|
}
|
2019-10-26 16:39:25 +02:00
|
|
|
|
2019-10-28 22:14:42 +01:00
|
|
|
int main(int argc, char **argv) {
|
2019-11-06 12:17:23 +01:00
|
|
|
|
|
|
|
int color_map[window_width][window_height];
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int j = 0; j < 100; j++) {
|
|
|
|
color_map[i][j] = 0xff000000;
|
2019-10-28 22:14:42 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 12:17:23 +01:00
|
|
|
My_Window *window = new My_Window(window_width, window_height, "example", &color_map);
|
2019-10-26 16:39:25 +02:00
|
|
|
window->begin();
|
2019-11-06 12:17:23 +01:00
|
|
|
Fl::repeat_timeout(0.5, refresh,window);//refresh anrufen nach 0.5 sec
|
|
|
|
Fl::repeat_timeout(1,change_color, &color_map);// change_color anrufen nach 1 sec
|
|
|
|
|
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();
|
|
|
|
} // main
|