> >
> > On 30 May 2012, at 22:23, Casey wrote:
> >
> > > 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!
> >
> > Or you could just look in the links pages for "anti paint" and study =
> > that code - that's a pretty good re-implementation of a paint-style =
> > pixel pusher, though was done for a quite old version of fltk so I'm not =
> > sure whether it will build with current fltk libs or not.
> >
> > Still, worth looking at for the educational value of nothing else.
> >
> >
> Thank you Ian, the link I am getting isn't active anymore, you wouldn't 
> happen to have an active link would you? Thank you for the help again.
>
> http://studwww.rug.ac.be/~hyperman/antipaint/download.html


I was generously provided with an active link here:
http://sowearedads.com/videos/antipaint.zip

I also found another source code here:

#include <Fl/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <Fl/Fl_Box.H>
#include <Fl/fl_draw.H>
#define window_size 400
static Fl_Double_Window *main_window = 0; // the main app window
static Fl_Offscreen offscreen_buffer = 0; // the offscreen surface
/*****************************************************************************/
/* This class provides a view to copy the offscreen surface to */
class canvas : public Fl_Box {
void draw();
int handle(int event);
public:
canvas(int x, int y, int w, int h);
};
/*****************************************************************************/
/* Constructor */
canvas::canvas(int x, int y, int w, int h) : Fl_Box(x,y,w,h){
} // Constructor
/*****************************************************************************/
void canvas::draw() {
if(offscreen_buffer) { // offscreen exists
// blit the required view from the offscreen onto the box
fl_copy_offscreen(x(), y(), w(), h(), offscreen_buffer, 0,0);
}
else { // create the offscreen
main_window->make_current(); //ensures suitable graphic context
offscreen_buffer = fl_create_offscreen( w(), h() );
if(!offscreen_buffer){fprintf(stderr,"Failed buffer creation"); exit(1);}
fl_begin_offscreen(offscreen_buffer); /* Open the offscreen context */
fl_color(FL_WHITE);
fl_rectf(0, 0, w(), h() );
fl_end_offscreen(); /* close the offscreen context */
/* init screen with offscreen buffer */
fl_copy_offscreen(x(), y(), w(), h(), offscreen_buffer, 0,0);
}
} // draw method
/*****************************************************************************/
int canvas::handle(int event) {
static char labeltext[100];
int button,x,y;
int retvalue = 0;
static int x_old,y_old;
static int push1st=0;
if (!offscreen_buffer) return 1;
retvalue = Fl_Box::handle(event);
switch (event) {
case FL_PUSH:
case FL_DRAG:
button = Fl::event_button();
x = Fl::event_x();
y = Fl::event_y();
};
switch ( button ) {
case 1: // Left button
sprintf(labeltext,"Last mouse button= Left | Mouse at %d,%d now",x,y);
window()->label(labeltext);
retvalue = 1;
break;
case 3: // Right button
sprintf(labeltext,"Last mouse button= Right | Mouse at %d,%d now",x,y);
window()->label(labeltext);
retvalue = 1;
break;
}
switch(event) {
case FL_PUSH:
if (push1st == 0) {
x_old = x;
y_old = y;
push1st = 1;
break;
} else {
push1st = 0;
/* Open the offscreen context for drawing */
fl_begin_offscreen(offscreen_buffer);
if (button==1){ //left mouse button
fl_color(FL_RED);
fl_line(x_old,y_old,x,y);
} else { //right mouse button
fl_draw_box(FL_BORDER_FRAME,x_old,y_old,(x-x_old),
(y-y_old),FL_BLUE);
}
fl_end_offscreen(); /* close the offscreen context */
redraw();
}
case FL_DRAG:
{push1st=0; //clear if dragging
/* Open the offscreen context for drawing */
fl_begin_offscreen(offscreen_buffer);
fl_color(FL_BLACK);
fl_point(x,y);
fl_end_offscreen(); // close the offscreen context
redraw();}
break;
default:
redraw();
break;
}
return retvalue;
} // handle
/*****************************************************************************/
int main (int argc, char **argv) {
main_window = new Fl_Double_Window(window_size, window_size,
"Drawing with mouse example");
main_window->begin();
// a view of the offscreen, inside the main window
static canvas *os_box = new canvas(5,5,(window_size-10),(window_size-10));
main_window->end();
main_window->resizable(os_box);
main_window->show(argc, argv);
return Fl::run();
} // main


I am getting errors with the offscreen functions when compiling this, am I 
missing a header file? or some linking issue?

main.cpp(10) : error C2146: syntax error : missing ';' before identifier 
'offscreen_buffer'
main.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ 
does not support default-int
main.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ 
does not support default-int
main.cpp(27) : error C3861: 'fl_copy_offscreen': identifier not found
main.cpp(31) : error C3861: 'fl_create_offscreen': identifier not found
main.cpp(33) : error C3861: 'fl_begin_offscreen': identifier not found
main.cpp(36) : error C3861: 'fl_end_offscreen': identifier not found
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to