I did it!
The main function:
private void DrawObjectSelection(SpriteBatch spriteBatch, Rectangle r) { r = Telecamera.Transform(r); Vector2 v1 = new Vector2(rX, rY); Vector2 v2 = new Vector2(rX + r.Width, rY); Vector2 v3 = new Vector2(rX, rY + r.Height); Vector2 v4 = new Vector2(rX + r.Width, rY + r.Height); //The side rectangle DrawEmptyRectangle(spriteBatch, v1, v2, v3, v4); //4 squares at vertices DrawFilledSquare(spriteBatch, v1); DrawFilledSquare(spriteBatch, v2); DrawFilledSquare(spriteBatch, v3); DrawFilledSquare(spriteBatch, v4); //the other 4 in the middle of every side float height = v4.Y - v1.Y; float width = v2.X - v1.X; DrawFilledSquare(spriteBatch, new Vector2(v1.X, v1.Y + height / 2)); DrawFilledSquare(spriteBatch, new Vector2(v2.X, v2.Y + height / 2)); DrawFilledSquare(spriteBatch, new Vector2(v1.X + width / 2, v1.Y)); DrawFilledSquare(spriteBatch, new Vector2(v1.X + width / 2, v4.Y)); }
Using these functions:
private void DrawLine( SpriteBatch spriteBatch, float width, Vector2 point1, Vector2 point2) { float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X); float length = Vector2.Distance(point1, point2); spriteBatch.Draw( grid_texture, point1, null, selection_color, angle, Vector2.Zero, new Vector2(length, width), SpriteEffects.None, 0); } private void DrawEmptyRectangle( SpriteBatch spriteBatch, Vector2 v1, Vector2 v2, Vector2 v3, Vector2 v4) { DrawLine(spriteBatch, 1.0f, v1, v2); DrawLine(spriteBatch, 1.0f, v1, v3); DrawLine(spriteBatch, 1.0f, v2, v4); DrawLine(spriteBatch, 1.0f, v3, v4); } private void DrawFilledSquare( SpriteBatch spriteBatch, Vector2 c_pos)
When I want to draw it, I need a rectangle, for example:
The only thing missing is click processing on each square. This is done using the simple “Contains” test with the mouse position coordinate.
Result Screen:
