-
Notifications
You must be signed in to change notification settings - Fork 53
/
ScreenshotSettings.cs
78 lines (66 loc) · 1.5 KB
/
ScreenshotSettings.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ScreenshotSettings
{
public const float IDEAL_ASPECT_RATIO = 16.0f / 9.0f;
//public const float IDEAL_ASPECT_RATIO = 1f;
private int mMaxWidth;
private int mMaxHeight;
public const int MIN_HEIGHT = 128;
public const int MIN_WIDTH = (int)(MIN_HEIGHT * IDEAL_ASPECT_RATIO);
public const int MAX_HEIGHT = 512;
public const int MAX_WIDTH = (int)(MAX_HEIGHT * IDEAL_ASPECT_RATIO);
public ScreenshotSettings()
{
maxHeight = 256; //Default
}
public int maxWidth
{
set
{
mMaxWidth = Math.Min(Math.Max(value, MIN_WIDTH), MAX_WIDTH);
mMaxHeight = (int)Math.Round(mMaxWidth/IDEAL_ASPECT_RATIO);
}
get
{
return mMaxWidth;
}
}
public int maxHeight
{
set
{
mMaxHeight = Math.Min(Math.Max(value, MIN_HEIGHT), MAX_HEIGHT);
mMaxWidth = (int)Math.Round(mMaxHeight*IDEAL_ASPECT_RATIO);
}
get
{
return mMaxHeight;
}
}
public void getBoundedDimensions(int width, int height, ref int bounded_w, ref int bounded_h)
{
float aspect = (float)width / (float)height;
if (aspect > IDEAL_ASPECT_RATIO)
{
//Wider than ideal aspect ratio
bounded_w = maxWidth;
bounded_h = Math.Min(maxHeight, (int)Math.Round(maxWidth / aspect));
}
else
{
//Taller than ideal aspect ratio
bounded_h = maxHeight;
bounded_w = Math.Min(maxWidth, (int)Math.Round(maxHeight * aspect));
}
}
public int maxNumBytes
{
get
{
return maxWidth * maxHeight * 3;
}
}
}