-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCropMargins.cs
79 lines (73 loc) · 2.26 KB
/
CropMargins.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CropperDeck {
public struct CropMargins {
public static CropMargins Zero = new CropMargins("No crop");
public static List<CropMargins> Default = new List<CropMargins>() {
new CropMargins("No crop"),
new CropMargins("Thin", 2, 32, 2, 2),
new CropMargins("Standard", 8, 32, 8, 8),
new CropMargins("Browser", 2, 39, 2, 2),
};
public static List<CropMargins> Special = new List<CropMargins>() {
new CropMargins("Special: Auto-Crop\u2122", GetAutoCropMargins),
};
/// <summary>Contributed by @Spitfire_x86</summary>
private static CropMarginsResult GetAutoCropMargins(DeckWindow window) {
var handle = window.Handle;
var style = (uint)WinAPI.GetWindowLong(handle, WinAPI_GWL.GWL_STYLE);
var exStyle = (uint)WinAPI.GetWindowLong(handle, WinAPI_GWL.GWL_EXSTYLE);
var rect = new WinAPI_Rect(0, 0, 0, 0); // we just want margins, so adjusted rect is 0
WinAPI.AdjustWindowRectEx(ref rect, style, false, exStyle);
// AdjustWindowRectEx adjusts the rect outwards, so left and top are negative
return new CropMarginsResult(-rect.Left, -rect.Top, rect.Right, rect.Bottom);
}
public string Name;
public int Top, Left, Right, Bottom;
public Func<DeckWindow, CropMarginsResult> Func;
public CropMargins(string name) {
Name = name;
Top = 0;
Left = 0;
Right = 0;
Bottom = 0;
Func = null;
}
public CropMargins(string name, int left, int top, int right, int bottom) {
Name = name;
Left = left;
Top = top;
Right = right;
Bottom = bottom;
Func = null;
}
public CropMargins(string name, Func<DeckWindow, CropMarginsResult> func) {
Name = name;
Left = 0;
Top = 0;
Right = 0;
Bottom = 0;
Func = func;
}
// just so we don't have a hardcoded string in 5 different places
public static readonly string AutoCropName = "Auto";
}
public struct CropMarginsResult {
public int Top, Left, Right, Bottom;
public CropMarginsResult(int left, int top, int right, int bottom) {
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public CropMarginsResult(CropMargins m) {
Left = m.Left;
Top = m.Top;
Right = m.Right;
Bottom = m.Bottom;
}
}
}