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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Core.DI;
using Tango.FSE.Common;
using Tango.FSE.Common.FSEApplication;
using Tango.FSE.Common.Resolution;
using Tango.FSE.UI.DemoMode;
using Tango.Settings;
namespace Tango.FSE.UI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
public static MainWindow Instance { get; set; }
private Point _startPoint;
private bool _isMouseDown;
private FSESettings _settings;
private IResolutionService _resolutionService;
public MainWindow()
{
Instance = this;
InitializeComponent();
_settings = SettingsManager.Default.GetOrCreate<FSESettings>();
ApplyAdaptiveTransform();
IFSEApplicationManager appManager = TangoIOC.Default.GetInstance<IFSEApplicationManager>();
ContentRendered += (_, __) =>
{
if (appManager.DemoMode)
{
DemoModeWindow demoWindow = new DemoModeWindow();
demoWindow.Show();
}
};
Closing += (x, e) =>
{
e.Cancel = true;
appManager.ShutDown();
};
btnMinimize.Click += (_, __) => WindowState = WindowState.Minimized;
btnMaximize.Click += (_, __) => WindowState = WindowState == WindowState.Maximized ? WindowState = WindowState.Normal : WindowState = WindowState.Maximized;
btnClose.Click += (_, __) => Close();
gridTitle.MouseLeftButtonDown += (x, e) =>
{
Mouse.Capture(gridTitle);
_startPoint = e.GetPosition(this);
if (e.ClickCount > 1 && appManager.DisplayWindowControls)
{
WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
return;
}
_isMouseDown = true;
};
gridTitle.MouseLeftButtonUp += (x, e) =>
{
_isMouseDown = false;
gridTitle.ReleaseMouseCapture();
};
gridTitle.MouseMove += GridTitle_MouseMove;
StateChanged += MainWindow_StateChanged;
}
private void MainWindow_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Maximized)
{
btnMaximize.Icon = MaterialDesignThemes.Wpf.PackIconKind.WindowRestore;
_settings.WindowMaximizedOnStartup = true;
_settings.Save();
}
else if (WindowState == WindowState.Normal)
{
btnMaximize.Icon = MaterialDesignThemes.Wpf.PackIconKind.WindowMaximize;
_settings.WindowMaximizedOnStartup = false;
_settings.Save();
}
}
private void GridTitle_MouseMove(object sender, MouseEventArgs e)
{
if (_isMouseDown)
{
if (WindowState == WindowState.Maximized)
{
var previousWidth = Width;
WindowState = WindowState.Normal;
var currentWidth = Width;
var locationPrecentageBefore = _startPoint.X / previousWidth;
var newLocationX = currentWidth * locationPrecentageBefore;
_startPoint = new Point(newLocationX, _startPoint.Y);
}
else
{
Point pointToWindow = Mouse.GetPosition(this);
Point pointToScreen = PointToScreen(pointToWindow);
Left = pointToScreen.X - _startPoint.X;
Top = pointToScreen.Y - _startPoint.Y;
}
}
}
private void ApplyAdaptiveTransform()
{
var resolution = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size;
if (_resolutionService == null)
{
_resolutionService = TangoIOC.Default.GetInstance<IResolutionService>();
}
if (_settings.EnableAdaptiveScaling && resolution.Width < 1600)
{
_resolutionService.AdaptiveScalingMode = true;
var grid = mainGrid;
grid.Width = 1920;
grid.Height = 1040;
Content = null;
Content = new Viewbox()
{
Child = mainGrid,
Stretch = Stretch.Fill,
};
var ratio = 1280d / 720d;
MinWidth = resolution.Width / (1920d / 1280d);
MinHeight = MinWidth / ratio;
Width = resolution.Width - 100;
Height = Width / ratio;
}
else
{
IgnoreTaskbarOnMaximize = resolution.Height <= 768; //Allow full screen when resolution is small.
}
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height < Height)
{
Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
}
}
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
base.OnRenderSizeChanged(sizeInfo);
//Add this to keep aspect ratio when AdaptiveTransform
//if (_resolutionService.AdaptiveTransformMode)
//{
// var aspect = 1920d / 1040d;
// if (sizeInfo.WidthChanged) this.Width = sizeInfo.NewSize.Height * aspect;
// else this.Height = sizeInfo.NewSize.Width / aspect;
//}
}
}
}
|