Don’t stop reading, just because I’m going to say something about a paint program!!! ;D
I’m trying to figure out how to make a ‘stamp’ for a paint program.
I want the user to click on a small icon, say a picture of a tree. Where ever the mouse is moved in the drawing area, the tree stamp will follow. When the mouse is clicked it will stamp the tree down.
Right now I have a custom JPanel which tracks where the mouse is and lets you draw. Since I’m drawing directly to the Graphics context, I don’t ‘know’ whats actually been drawn.
So, if I’m moving the stamp around the screen, it shouldn’t destroy what is already there. I have 2 thoghts on how to do this -
1 - Figure out where the mouse is. Copy the image data at that location into a temporary image. Blit my tree where the mouse is. When the mouse moves. blit the temporary image to where the mouse was, then start at the beginning again.
2 - Draw to the panel like now, but also draw to a back buffer. When the mouse moves, blit the area of the stamp from the back buffer onto the current graphics context.
Do these sound like they will work? What about flicker issues?