Hello guys!, so this is my problem, i'm trying to make a paint-like program in C++ using the WinBGIm libraries (im using Dev-C++), so i need to program a paint brush. Here's what i've managed to code:
1)Create a canvas
2)Create a clickable button (it just returns if it is selected or not, if it is toggled on i can paint on the canvas, if not, i cannot, got no problem with that)
3)And the problem is that when i click my button (and its toggled on), i've set a method to recognize if i click the canvas and then paint on it, but i can't seem to figure out how to make it paint a continous trail instead of just one by one points /:
Here is the code of the "listener":
//This is my main class
Canvas l1=Canvas(64,42,960,598); //just a simple rectangle
Button b1=Button(8,42,32,32); //just a square
b1.show();
bool a=true; //create a variable to set the toggle on the button
while(!kbhit()){ //i set it to exit on keypress temporarily
clearmouseclick(WM_LBUTTONDOWN);
if(mousex()>b1.x && mousex()<b1.x2 && mousey()>b1.y && mousey()<b1.y2 && ismouseclick(WM_LBUTTONDOWN))
{
b1.setSel(a);
if(a){a=false;}
else{a=true;}
clearmouseclick(WM_LBUTTONDOWN);
//just toggling the button no prob with that
}
else if(mousex()>l1.x && mousex()<l1.xf && mousey()>l1.y && mousey()<l1.yf && b1.isSelected() && ismouseclick(WM_LBUTTONDOWN))
{
b1.Accion(l1.x,l1.xf,l1.y,l1.yf); //THIS is the one im having problems with
}
}
And, this is the code of the method:
//This is inside my Button class
void Accion(int a, int b, int c, int d)
{
do{
if(mousex()>a && mousex()<b && mousey()>c && mousey()<d && ismouseclick(WM_LBUTTONDOWN)) //re-compare with the bounds of the canvas so it does not paint outside them
{
if(ismouseclick(WM_MOUSEMOVE)) //if i move it, it is supposed to follow mouse movement, but it just paints one circle at a time everytime i click the canvas
{
circle(mousex(),mousey(),1);
}
}
}while(!ismouseclick(WM_LBUTTONUP)); //this is to detect when i stop pressing the mouse but still got no clue how to do this the right way
}
Well, so hope you guys can help me out in this one!! Thanks in advance!