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

有帮助吗?

解决方案 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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top