/
RectangleShape.cs
95 lines (88 loc) · 3.32 KB
/
RectangleShape.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Runtime.InteropServices;
using System.Security;
using SFML.Window;
namespace SFML
{
namespace Graphics
{
////////////////////////////////////////////////////////////
/// <summary>
/// Specialized shape representing a rectangle
/// </summary>
////////////////////////////////////////////////////////////
public class RectangleShape : Shape
{
////////////////////////////////////////////////////////////
/// <summary>
/// Default constructor
/// </summary>
////////////////////////////////////////////////////////////
public RectangleShape() :
this(new Vector2f(0, 0))
{
}
////////////////////////////////////////////////////////////
/// <summary>
/// Construct the shape with an initial size
/// </summary>
/// <param name="size">Size of the shape</param>
////////////////////////////////////////////////////////////
public RectangleShape(Vector2f size)
{
Size = size;
}
////////////////////////////////////////////////////////////
/// <summary>
/// Construct the shape from another shape
/// </summary>
/// <param name="copy">Shape to copy</param>
////////////////////////////////////////////////////////////
public RectangleShape(RectangleShape copy) :
base(copy)
{
Size = copy.Size;
}
////////////////////////////////////////////////////////////
/// <summary>
/// The size of the rectangle
/// </summary>
////////////////////////////////////////////////////////////
public Vector2f Size
{
get { return mySize; }
set { mySize = value; Update(); }
}
////////////////////////////////////////////////////////////
/// <summary>
/// The total number of points of the shape
/// </summary>
////////////////////////////////////////////////////////////
public override uint PointCount
{
get { return 4; }
}
////////////////////////////////////////////////////////////
/// <summary>
/// Get a point of the shape.
///
/// The result is undefined if index is out of the valid range.
/// </summary>
/// <param name="index">Index of the point to get, in range [0 .. PointCount - 1]</param>
/// <returns>Index-th point of the shape</returns>
////////////////////////////////////////////////////////////
public override Vector2f GetPoint(uint index)
{
switch (index)
{
default:
case 0: return new Vector2f(0, 0);
case 1: return new Vector2f(mySize.X, 0);
case 2: return new Vector2f(mySize.X, mySize.Y);
case 3: return new Vector2f(0, mySize.Y);
}
}
private Vector2f mySize;
}
}
}