1.remake show the bild

2.the GUI can show a bild with the colormap
3.Kommentar
This commit is contained in:
chenhuan 2019-11-06 12:17:23 +01:00
parent e6259c46e1
commit 7ddea2b130

View File

@ -2,69 +2,138 @@
#include <iostream> #include <iostream>
#include <Fl/Fl.H> #include <Fl/Fl.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/Fl_Timer.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#define window_height 600 #define window_height 600
#define window_width 800 #define window_width 800
/*****************************************************************************/ /**************************************[[l***************************************/
/* This class provides a view to copy the offscreen surface to */ /* This class provides a view to copy the offscreen surface to */
int color_map[window_width][window_height]; //Pixel ist ein neue Class fuer ein Pixel
class My_Window : public Fl_Window{ class Pixel : public Fl_Widget {
int x,y,button; Fl_Color color;
int handle(int e) //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);
}
switch (e) 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));
}
};
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
case FL_MOVE: case FL_MOVE:
x = Fl::event_x(); x = Fl::event_x();
y = Fl::event_y(); y = Fl::event_y();
std::cout<<"Postion X:"<< x <<" Postion Y:"<< y <<std::endl; std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
return 1; return 1;
//Druck von der Tastator behandln
case FL_KEYBOARD: case FL_KEYBOARD:
button = Fl::event_button(); button = Fl::event_button();
std::cout<<"Keyboard:"<< (unsigned short)button <<std::endl; std::cout << "Keyboard:" << (unsigned short) button << std::endl;
return 1; return 1;
// case FL_:
} }
} }
public: public:
My_Window(int x, int y, const char *l ) : Fl_Window(x,y,l){}; //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;
class Pixel : public Fl_Widget { for (int i = 0; i < window_width; i++) {
Fl_Color color; for (int j = 0; j < window_height; j++) {
void draw(){ pixels[i][j]=new Pixel(i,j,1,1);
fl_draw_box(static_cast<Fl_Boxtype>(1), x(), y(), w(), h(), color); }
}
} }
//Window akualisieren, refresh
public: int draw_bild() {
Pixel(int x,int y,int w,int h,int RGB) : for (int i = 0; i < window_width; i++) {
Fl_Widget(x,y,w,h,0) { for (int j = 0; j < window_height; j++) {
this->color = fl_rgb_color((uchar)((RGB&0xff000000)>>24),(uchar)((RGB&0xff0000)>>16),(uchar)((RGB&0xff00)>>8)); pixels[i][j]->set_color((*color_map)[i][j]);
pixels[i][j]->redraw();
}
}
} }
}; };
//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;
}
}
Fl::repeat_timeout(1, change_color,pointer);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
for(int i=0;i<100;i++){
for (int j = 0; j < 100 ; j++) { int color_map[window_width][window_height];
color_map[i][j]=0xff000000;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
color_map[i][j] = 0xff000000;
} }
} }
My_Window* window = new My_Window(window_width, window_height, "example"); My_Window *window = new My_Window(window_width, window_height, "example", &color_map);
window->begin(); window->begin();
for(int i=0;i<100;i++){ Fl::repeat_timeout(0.5, refresh,window);//refresh anrufen nach 0.5 sec
for (int j = 0; j < 100 ; j++) { Fl::repeat_timeout(1,change_color, &color_map);// change_color anrufen nach 1 sec
new Pixel(i,j,1,1,color_map[i][j]);
}
}
window->end(); window->end();
window->show(argc,argv); window->show(argc, argv);
return Fl::run(); return Fl::run();
} // main } // main