Android Question Drawing Negative Rectangles

ondesic

Active Member
Licensed User
I have a canvas where I draw a rectangle on.
If the rect is: Left = 100, Top = 100, Right = 200, Bottom = 200.
I use both Invalidate2(rect) and Invalidate3(the coodinates)
The rectangle draws perfect.

However, if I make the rect: Left = 100, Top = 100, Right = 0, Bottom = 0.
The image will not draw at all if I use Invalidate2 or Invalidate3.
I have to use Invalidate.

This leads me to believe that Invalidate2 and 3 DO NOT take in consideration a negative rectangle, even though the drawRect method DOES draw a negative rectangle.

Can this be fixed?
 

DonManfred

Expert
Licensed User
Upvote 0

ondesic

Active Member
Licensed User
Shouldn't "Invalidate" use the same rectangle as DrawRect function? If this is the case, then something is wrong.
Remember, DrawRect will use the negative rectangle and draw just fine. It's the Invalidate2 and 3 that is not drawing correctly.

I have to use a negative rectangle because the user needs to be able to touch the screen and drag forward or backwards. When they let go, the rectangle is drawn.
I have tested this a many times. IF the rectangle is negative, Invalidate2 and 3 (and only these two) will not redraw the screen correctly.

Does that make sense?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
I'm not sure if this is really to be classed as a bug as you would not normally expect to issue the inverse rectangle when invalidating part of the Activity or Panel. But I can see how it is causing you a problem in this scenario.
You can still make it work with Invalidate3 and your coordinates if you do something like this...
B4X:
Activity.Invalidate3(Min(Left, Right), Min(Top, Bottom), Max(Left, Right), Max(Top, Bottom))
Untested but should work.
 
Upvote 0
Top