So I am trying to replicate my own version of mspaint with fltk. I have two 
problems, my first problem is that I am limited to a certain number of points. 
My current method is using a predetermined amount of points(line 46: point 
points[1000]; ) Is there a better method that just adjusts the amount of points 
according to the user's input instead of limiting the number of points to 
1000??? This presents another issue where the color is changing every point, 
instead of the current point the user is working on. Any help wouldbe greatly 
appreciated! Thanx!

#include <FL/Fl.h>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <Fl/Fl_Window.h>
#include <Fl/fl_draw.h>

int color_num = FL_BLACK;

struct point {
        point(){ x = 0 ; y = 0; }
        int x;
        int y;
};

class canvas : public Fl_Box {
        public:
                canvas(int x, int y, int w, int h, const char *lab = 0) : 
Fl_Box(x, y, w, h, lab){
                        Fl_Box::box(FL_ENGRAVED_BOX);
                        Fl_Box::color(FL_WHITE);
                        index = 0;
}

int handle(int event){
        if (event == FL_PUSH) {
                return 1;
        }
        else if (event == FL_DRAG){
                points[index].x = Fl::event_x();
                points[index].y = Fl::event_y();
                index++;
                redraw();
                return 1;
        }
}

void draw(void){
        Fl_Box::draw();
        fl_color(color_num);
        for(int i = 0; i < 999; i++) {
                fl_point(points[i].x,points[i].y);
        }
}

int index;
        point points[1000];
};

void blueButton_cb(Fl_Widget *w, void *data) {
        color_num = FL_BLUE;
}

int main(int argc, char **argv) {
        Fl_Window *window = new Fl_Window(400, 400, "Draw Something");
        Fl_Button *blueButton = new Fl_Button(310, 10, 20, 20);

        blueButton->callback(blueButton_cb);
        blueButton->color(216);
        blueButton->tooltip("Blue");

        canvas c(0, 0, 300, 300);
        c.show();

        window->end();
        window->show(argc, argv);

        return Fl::run();
}



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to