cbreemer
Bronze Coder
I am having fun with drawing stuff on a Canvas using Graphics2D. Basically I want to mimic a Form Editor like that of Visual Studio, where you can paint a component on the screen by drawing rectangle with the mouse. Essentially, the rectangle should grow or shrink as long as the mouse is being moved, only to be fixed when the mouse button is released. So with every mouse movement, the previously drawn rectangle should be wiped. To achieve this, before drawing the new rectangle, I restore a snapshot of the canvas that was taken when the mouse button went down.
This works well enough, the flickering is understandable but not too disturbing when you keep some continuous movement in the mouse. But what I fail to understand is why the rectangle disappears as soon as I stop the mouse movement for more than a split second. Ok, all is well once I let go of the mouse button, but this annoying.
Phew, not easy describing this issue. Best provide some code. Instead of posting the code here I decided to be modern for a change and put it on Codepen : https://codepen.io/cbreemer/pen/mdgOQdQ
Just draw a rectangle on the blank canvas and you'll see what I mean. I wonder is I'm missing something obvious here.
This works well enough, the flickering is understandable but not too disturbing when you keep some continuous movement in the mouse. But what I fail to understand is why the rectangle disappears as soon as I stop the mouse movement for more than a split second. Ok, all is well once I let go of the mouse button, but this annoying.
Phew, not easy describing this issue. Best provide some code. Instead of posting the code here I decided to be modern for a change and put it on Codepen : https://codepen.io/cbreemer/pen/mdgOQdQ
Just draw a rectangle on the blank canvas and you'll see what I mean. I wonder is I'm missing something obvious here.