139 lines
4.5 KiB
C++
139 lines
4.5 KiB
C++
|
|
#include <iostream>
|
|
#include <Fl/Fl.H>
|
|
#include <FL/Fl_Box.H>
|
|
#include <FL/Fl_Timer.H>
|
|
#include <FL/Fl_Window.H>
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
|
#define window_height 600
|
|
#define window_width 800
|
|
|
|
/**************************************[[l***************************************/
|
|
/* This class provides a view to copy the offscreen surface to */
|
|
|
|
//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));
|
|
}
|
|
};
|
|
|
|
|
|
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:
|
|
x = Fl::event_x();
|
|
y = Fl::event_y();
|
|
std::cout << "Postion X:" << x << " Postion Y:" << y << std::endl;
|
|
return 1;
|
|
//Druck von der Tastator behandln
|
|
case FL_KEYBOARD:
|
|
button = Fl::event_button();
|
|
std::cout << "Keyboard:" << (unsigned short) button << std::endl;
|
|
return 1;
|
|
// case FL_:
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
//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();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
//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 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;
|
|
}
|
|
}
|
|
My_Window *window = new My_Window(window_width, window_height, "example", &color_map);
|
|
window->begin();
|
|
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
|
|
|
|
window->end();
|
|
window->show(argc, argv);
|
|
return Fl::run();
|
|
} // main
|