GUI/main/main.cpp

70 lines
1.7 KiB
C++

#include <iostream>
#include <Fl/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
#define window_height 600
#define window_width 800
/*****************************************************************************/
/* This class provides a view to copy the offscreen surface to */
int color_map[window_width][window_height];
class My_Window : public Fl_Window{
int x,y,button;
int handle(int e)
{
switch (e)
{
case FL_MOVE:
x = Fl::event_x();
y = Fl::event_y();
std::cout<<"Postion X:"<< x <<" Postion Y:"<< y <<std::endl;
return 1;
case FL_KEYBOARD:
button = Fl::event_button();
std::cout<<"Keyboard:"<< (unsigned short)button <<std::endl;
return 1;
}
}
public:
My_Window(int x, int y, const char *l ) : Fl_Window(x,y,l){};
};
class Pixel : public Fl_Widget {
Fl_Color color;
void draw(){
fl_draw_box(static_cast<Fl_Boxtype>(1), x(), y(), w(), h(), color);
}
public:
Pixel(int x,int y,int w,int h,int RGB) :
Fl_Widget(x,y,w,h,0) {
this->color = fl_rgb_color((uchar)((RGB&0xff000000)>>24),(uchar)((RGB&0xff0000)>>16),(uchar)((RGB&0xff00)>>8));
}
};
int main(int argc, char **argv) {
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");
window->begin();
for(int i=0;i<100;i++){
for (int j = 0; j < 100 ; j++) {
new Pixel(i,j,1,1,color_map[i][j]);
}
}
window->end();
window->show(argc,argv);
return Fl::run();
} // main