Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
3
 * See license.txt for license info
4
 */
5
#endregion
6
 
7
using System;
8
using System.Collections.Generic;
9
using System.Text;
10
using System.Runtime.InteropServices;
11
namespace OpenTK
12
{
13
    /// <summary>
14
    /// Defines a 2d box (rectangle).
15
    /// </summary>
16
    [StructLayout(LayoutKind.Sequential)]
17
    public struct Box2
18
    {
19
        /// <summary>
20
        /// The left boundary of the structure.
21
        /// </summary>
22
        public float Left;
23
 
24
        /// <summary>
25
        /// The right boundary of the structure.
26
        /// </summary>
27
        public float Right;
28
 
29
        /// <summary>
30
        /// The top boundary of the structure.
31
        /// </summary>
32
        public float Top;
33
 
34
        /// <summary>
35
        /// The bottom boundary of the structure.
36
        /// </summary>
37
        public float Bottom;
38
 
39
        /// <summary>
40
        /// Constructs a new Box2 with the specified dimensions.
41
        /// </summary>
42
        /// <param name="topLeft">AnOpenTK.Vector2 describing the top-left corner of the Box2.</param>
43
        /// <param name="bottomRight">An OpenTK.Vector2 describing the bottom-right corner of the Box2.</param>
44
        public Box2(Vector2 topLeft, Vector2 bottomRight)
45
        {
46
            Left = topLeft.X;
47
            Top = topLeft.Y;
48
            Right = topLeft.X;
49
            Bottom = topLeft.Y;
50
        }
51
 
52
        /// <summary>
53
        /// Constructs a new Box2 with the specified dimensions.
54
        /// </summary>
55
        /// <param name="left">The position of the left boundary.</param>
56
        /// <param name="top">The position of the top boundary.</param>
57
        /// <param name="right">The position of the right boundary.</param>
58
        /// <param name="bottom">The position of the bottom boundary.</param>
59
        public Box2(float left, float top, float right, float bottom)
60
        {
61
            Left = left;
62
            Top = top;
63
            Right = right;
64
            Bottom = bottom;
65
        }
66
 
67
        /// <summary>
68
        /// Creates a new Box2 with the specified dimensions.
69
        /// </summary>
70
        /// <param name="top">The position of the top boundary.</param>
71
        /// <param name="left">The position of the left boundary.</param>
72
        /// <param name="right">The position of the right boundary.</param>
73
        /// <param name="bottom">The position of the bottom boundary.</param>
74
        /// <returns>A new OpenTK.Box2 with the specfied dimensions.</returns>
75
        public static Box2 FromTLRB(float top, float left, float right, float bottom)
76
        {
77
            return new Box2(left, top, right, bottom);
78
        }
79
 
80
        /// <summary>
81
        /// Gets a float describing the width of the Box2 structure.
82
        /// </summary>
83
        public float Width { get { return (float)System.Math.Abs(Right - Left); } }
84
 
85
        /// <summary>
86
        /// Gets a float describing the height of the Box2 structure.
87
        /// </summary>
88
        public float Height { get { return (float)System.Math.Abs(Bottom - Top); } }
89
 
90
        /// <summary>
91
        /// Returns a <see cref="System.String"/> describing the current instance.
92
        /// </summary>
93
        /// <returns></returns>
94
        public override string ToString()
95
        {
96
            return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom);
97
        }
98
    }
99
}