Projekt

Obecné

Profil

Stáhnout (2.24 KB) Statistiky
| Větev: | Tag: | Revize:
1
using System.Drawing;
2

    
3
namespace DeltaRobotVr.Launcher
4
{
5
    
6
    /// <summary>
7
    /// A rectangle that allows creating layouts with subtractive methods.
8
    /// </summary>
9
    public struct LayoutRectangle
10
    {
11
        public int Top;
12
        public int Right;
13
        public int Bottom;
14
        public int Left;
15

    
16
        public int Width => Right - Left;
17
        public int Height => Bottom - Top;
18

    
19
        public LayoutRectangle(int top, int right, int bottom, int left)
20
        {
21
            Top = top;
22
            Right = right;
23
            Bottom = bottom;
24
            Left = left;
25
        }
26

    
27
        public LayoutRectangle(Rectangle rect) : this(rect.Top, rect.Right, rect.Bottom, rect.Left)
28
        {
29
        }
30

    
31
        public Rectangle ToRectangle() => new Rectangle(Left, Top, Right - Left, Bottom - Top);
32

    
33
        public LayoutRectangle RemoveFromTop(int value)
34
        {
35
            if (value > Height)
36
            {
37
                value = Height;
38
            }
39
            
40
            var result = new LayoutRectangle(Top, Right, Top + value, Left);
41
            Top += value;
42
            return result;
43
        }
44

    
45
        public LayoutRectangle RemoveFromRight(int value)
46
        {
47
            if (value > Width)
48
            {
49
                value = Width;
50
            }
51
            
52
            var result = new LayoutRectangle(Top, Right, Bottom, Right - value);
53
            Right -= value;
54
            return result;
55
        }
56

    
57
        public LayoutRectangle RemoveFromBottom(int value)
58
        {
59
            if (value > Height)
60
            {
61
                value = Height;
62
            }
63
            
64
            var result = new LayoutRectangle(Bottom - value, Right, Bottom, Left);
65
            Bottom -= value;
66
            return result;
67
        }
68

    
69
        public LayoutRectangle RemoveFromLeft(int value)
70
        {
71
            if (value > Width)
72
            {
73
                value = Width;
74
            }
75
            
76
            var result = new LayoutRectangle(Top, Left + value, Bottom, Left);
77
            Left += value;
78
            return result;
79
        }
80

    
81
        public LayoutRectangle Shrink(int value)
82
        {
83
            Top += value;
84
            Right -= value;
85
            Bottom -= value;
86
            Left += value;
87
            return this;
88
        }
89
    }
90
}
(4-4/5)