1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
while(SDL_PollEvent( &event ) )
{
//While there is an event happening
if(event.type == SDL_MOUSEBUTTONDOWN)
{
//If the event is mouse button down
SDL_Rect drawing; //Declare a rectangle which will be drawn to screen (that variable name tho :P )
drawing.x = event.button.x; //The x value of the rectangle is the x location of the mouse
drawing.y = event.button.y; //The y value of the rectangle is the y location of the mouse
if(eraser == 1) //If the eraser is enabled
{
drawing.w = 50; //Set the width of the rectangle to 50 (for fast erase)
drawing.h = 50; //Set the height of the rectangle to 50 (for fast erase)
}
else //If the eraser is not enabled
{
drawing.w = 1; //Set the width of the drawing to 1 pixel
drawing.h = 1; //Set the height of the drawing to 1 pixel
}
//Fill the screen (1st argument) , with the drawing's properties (rectangle). We use the MapRGB function to take the color.
//We take the screen's format and set the red , green and blue values to the variables we declared before
SDL_FillRect(screen,&drawing,SDL_MapRGB(screen->format,red,green,blue));
SDL_Flip(screen); //Refresh the screen
mouseDown = 0; //Report that the mouse button is pressed.
}
else if(event.type == SDL_MOUSEBUTTONUP)
{
//If the mouse is left
mouseDown = 1; //Report that the mouse button IS NOT pressed.
}
else if(event.type == SDL_MOUSEMOTION)
{
//If the mouse moves
if(mouseDown == 0)
{
//Check if the mouse is pressed (check the variable we declared and changed/not changed before)
SDL_Rect drawing; //Declare a rectangle which will be drawn to screen (that variable name tho :P )
drawing.x = event.button.x; //The x value of the rectangle is the x location of the mouse
drawing.y = event.button.y; //The y value of the rectangle is the y location of the mouse
if(eraser == 1)//If the eraser is enabled
{
drawing.w = 50; //Set the width of the rectangle to 50 (for fast erase)
drawing.h = 50; //Set the height of the rectangle to 50 (for fast erase)
}
else //If the eraser is not enabled
{
drawing.w = 1; //Set the width of the drawing to 1 pixel
drawing.h = 1; //Set the height of the drawing to 1 pixel
}
//Fill the screen (1st argument) , with the drawing's properties (rectangle). We use the MapRGB function to take the color.
//We take the screen's format and set the red , green and blue values to the variables we declared before
SDL_FillRect(screen,&drawing,SDL_MapRGB(screen->format,red,green,blue));
SDL_Flip(screen); //Refresh the screen
}
}
|