summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Utilities/DPIAwareness.cs
blob: 91751474c01acffbfc59be5b5f22d39b71748c17 (plain)
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
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DPIAwareness.cs" company="HandBrake Project (http://handbrake.fr)">
//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
//   Defines the DPIAwareness type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.Utilities
{
    using System.Windows;
    using System.Windows.Media;

    /// <summary>
    /// The dpi awareness.
    /// </summary>
    public class DPIAwareness
    {
        /// <summary>
        /// The dx.
        /// </summary>
        private static double dx;

        /// <summary>
        /// The dy.
        /// </summary>
        private static double dy;

        /// <summary>
        /// Initializes a new instance of the <see cref="DPIAwareness"/> class.
        /// </summary>
        public DPIAwareness()
        {
            var presentationSource = PresentationSource.FromVisual(Application.Current.MainWindow);
            if (presentationSource != null && presentationSource.CompositionTarget != null)
            {
                Matrix m = presentationSource.CompositionTarget.TransformToDevice;
                dx = m.M11;
                dy = m.M22;
            }
        }

        /// <summary>
        /// Gets the dpix.
        /// </summary>
        public double Dpix
        {
            get
            {
                return dx;
            }
        }

        /// <summary>
        /// Gets the dpi y.
        /// </summary>
        public double DpiY
        {
            get
            {
                return dy;
            }
        }
    }
}