Question

https://i.stack.imgur.com/JQGTE.png

Can anyone share a code how to draw a rectangle like this? (not vertical, not horizontal, somewhere between) Because as I see you can only specify 4 ints to function DrawRect(), not 4 points.

The area of rectangle must be sensitive to touch (I use Contains() method)

As I tried, Matrix and Rotate() update only graphics, the rect's area remains the same it was

Was it helpful?

Solution 3

I found solution - the easiest way is to use Path class, make a free-turned rectangle by points and then create a region method, which has function Contains()

No need for math and hard work, pretty and easy.

OTHER TIPS

After transforming as @fortran suggested, you can use one of the Matrix.mapPoints overloads to find out what the new corners of your rectangle are. You'll probably have to find some fancy math and do hit testing yourself. Might be easier to call Matrix.mapPoints() on the inverse of the transformation used to draw the rectangle, passing the touched coordinates, and then hit test on the original rectangle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top