Domanda

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

È stato utile?

Soluzione 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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top