-
Notifications
You must be signed in to change notification settings - Fork 71
/
WindowsSizingBoxes.cs
108 lines (92 loc) · 4.15 KB
/
WindowsSizingBoxes.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
96
97
98
99
100
101
102
103
104
105
106
107
108
using Svg;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Win32Interop.Enums;
namespace EasyTabs
{
public class WindowsSizingBoxes
{
protected TitleBarTabs _parentWindow;
protected Image _minimizeImage = null;
protected Image _restoreImage = null;
protected Image _maximizeImage = null;
protected Image _closeImage = null;
protected Image _closeHighlightImage = null;
protected Brush _minimizeMaximizeButtonHighlight = new SolidBrush(Color.FromArgb(27, Color.Black));
protected Brush _closeButtonHighlight = new SolidBrush(Color.FromArgb(232, 17, 35));
protected Rectangle _minimizeButtonArea = new Rectangle(0, 0, 45, 29);
protected Rectangle _maximizeRestoreButtonArea = new Rectangle(45, 0, 45, 29);
protected Rectangle _closeButtonArea = new Rectangle(90, 0, 45, 29);
public WindowsSizingBoxes(TitleBarTabs parentWindow)
{
_parentWindow = parentWindow;
_minimizeImage = LoadSvg(Encoding.UTF8.GetString(Resources.Minimize), 10, 10);
_restoreImage = LoadSvg(Encoding.UTF8.GetString(Resources.Restore), 10, 10);
_maximizeImage = LoadSvg(Encoding.UTF8.GetString(Resources.Maximize), 10, 10);
_closeImage = LoadSvg(Encoding.UTF8.GetString(Resources.Close), 10, 10);
_closeHighlightImage = LoadSvg(Encoding.UTF8.GetString(Resources.CloseHighlight), 10, 10);
}
protected Image LoadSvg(string svgXml, int width, int height)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(svgXml);
return SvgDocument.Open(xmlDocument).Draw(width, height);
}
public int Width
{
get
{
return _minimizeButtonArea.Width + _maximizeRestoreButtonArea.Width + _closeButtonArea.Width;
}
}
public bool Contains(Point cursor)
{
return _minimizeButtonArea.Contains(cursor) || _maximizeRestoreButtonArea.Contains(cursor) || _closeButtonArea.Contains(cursor);
}
public void Render(Graphics graphicsContext, Point cursor)
{
int right = _parentWindow.ClientRectangle.Width;
bool closeButtonHighlighted = false;
_minimizeButtonArea.X = right - 135;
_maximizeRestoreButtonArea.X = right - 90;
_closeButtonArea.X = right - 45;
if (_minimizeButtonArea.Contains(cursor))
{
graphicsContext.FillRectangle(_minimizeMaximizeButtonHighlight, _minimizeButtonArea);
}
else if (_maximizeRestoreButtonArea.Contains(cursor))
{
graphicsContext.FillRectangle(_minimizeMaximizeButtonHighlight, _maximizeRestoreButtonArea);
}
else if (_closeButtonArea.Contains(cursor))
{
graphicsContext.FillRectangle(_closeButtonHighlight, _closeButtonArea);
closeButtonHighlighted = true;
}
graphicsContext.DrawImage(closeButtonHighlighted ? _closeHighlightImage : _closeImage, _closeButtonArea.X + 17, _closeButtonArea.Y + 9);
graphicsContext.DrawImage(_parentWindow.WindowState == FormWindowState.Maximized ? _restoreImage : _maximizeImage, _maximizeRestoreButtonArea.X + 17, _maximizeRestoreButtonArea.Y + 9);
graphicsContext.DrawImage(_minimizeImage, _minimizeButtonArea.X + 17, _minimizeButtonArea.Y + 9);
}
public HT NonClientHitTest(Point cursor)
{
if (_minimizeButtonArea.Contains(cursor))
{
return HT.HTMINBUTTON;
}
else if (_maximizeRestoreButtonArea.Contains(cursor))
{
return HT.HTMAXBUTTON;
}
else if (_closeButtonArea.Contains(cursor))
{
return HT.HTCLOSE;
}
return HT.HTNOWHERE;
}
}
}