Shapes won't erase

Dec 27, 2010 at 7:46pm
closed account (LTXN8vqX)
I was bored last night so i got a cool idea in my head, let me try to make my own cursor. Now, i did this by using the Rectangle() function. After i have made my shape, i told it to draw it again if the mouse coordinates have changed. My only problem is that it doesn't erase the shape it drew before it, so basically when i move my mouse, there is a trail of rectangles. How can i erase a shape?
Dec 28, 2010 at 6:45am
Hi.

1. What you need to do is copy the data behind the cursor before drawing.
I would use BitBlt to an off screen DC (using new Coords).

2. Then draw your cursor (using new Coords).

3. When it moves You need to first BitBlt from Offscreen DC to screen (using previous Coords).

Then start over again.

Hope this makes sense
Shredded
Dec 28, 2010 at 6:57am
closed account (LTXN8vqX)
lol, haven't reached bitmaps yet
Dec 28, 2010 at 6:59am
The easier way to do this is to just change the cursor.

Look up SetCursor on msdn
Dec 28, 2010 at 7:15am
closed account (LTXN8vqX)
lol, Disch if it was that easy i wouldn't be here. The problem isn't the cursor, it is the shape that i drew that looks like a cursor. It draws the shape the way i want but it doesn't erase it when it moves to a new position it just draws a new one which makes the screen messy with all the shapes. Thanks for your replies though.
Dec 28, 2010 at 7:50am
Well if the back ground of your window is static - you can use one one of two drawing modes to
achieve the effect you want.
Look up the SetROP2 windows api function - and in particular the R2_NOT and the R2_XORPEN options.

1. Always record the current position of your shape.

2. Set the drawing mode and Draw the shape

3. When it is time to move, then redraw the shape at the old position (this will erase it) and draw it
at the new position


*one thing to bear in mind is that a black pen is not a suitable colour to draw things with using R2_XORPEN*
Dec 28, 2010 at 4:19pm
geomike wrote:
i got a cool idea in my head, let me try to make my own cursor
geomike wrote:
The problem isn't the cursor, it is the shape that i drew that looks like a cursor.


I don't understand. You're trying to make your own cursor, but you're going about it in a way which doesn't use the cursor? Why can't you just change the cursor to be these shapes instead of drawing them?

If you want to do this the way you're attempting (which I don't recommend), then you'll have to redraw whatever is under the old cursor's position (thereby erasing the old cursor), then draw the cursor at its new position. You'll have to do that every time the cursor moves.

guestgulkan's idea is neat and might work, but only if you want a cursor that inverts the colors beneath it. If you want to draw a cursor that's the same color no matter what it's hovering over then his idea won't work (hence why he said the background of your window must be static).

Again, it would be a lot easier to just change the cursor.
Dec 29, 2010 at 12:00am
closed account (3pj6b7Xj)
Hey that sounds interesting! So SetROP2 copies the area the shape was on and you could restore the original background there? Wouldn't that cause flickering though?
Dec 29, 2010 at 11:40am
There is no copying.
The SetROP2 function sets how the pen colour you are drawing with mixes with the colours already
on the screen (in some rop modes, the pen may be completely ignored).

For example - say we have a red pen and our window background is also red.
say we set R2_NOT mode and try to draw a rectangle.
The R2_NOT mode means - ignore the pen and use the inverted colour of what is on the background. we said the RGB of the screen is red which is 255 0 0 - the inversion of this 0 255 255
which makes your rectangle a blueygreen colour - which contrast with the red background.
If you draw the reactangle again in the same spot using the same mode - then 0 255 255 -> 255 0 0 and you get a red rectangle on a red background - so effectively the rectangle looks as though
it has been erased.
Topic archived. No new replies allowed.