Skip to content

Commit a683a08

Browse files
committed
moved to evilbaschdi.core nuget package, ui adjustments, switched from german to english lables, button rotation, window resizing
1 parent 7f5edb1 commit a683a08

14 files changed

+299
-135
lines changed

DisplayRotation.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisplayRotation", "DisplayRotation\DisplayRotation.csproj", "{7A789136-B210-452D-A16B-20B5D8CCFE76}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EvilBaschdi.Core", "..\EvilBaschdi.Core\EvilBaschdi.Core\EvilBaschdi.Core.csproj", "{8A06A423-244F-404F-AAD8-53DE2EE2AED7}"
9-
EndProject
108
Global
119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1210
Debug|Any CPU = Debug|Any CPU
@@ -17,10 +15,6 @@ Global
1715
{7A789136-B210-452D-A16B-20B5D8CCFE76}.Debug|Any CPU.Build.0 = Debug|Any CPU
1816
{7A789136-B210-452D-A16B-20B5D8CCFE76}.Release|Any CPU.ActiveCfg = Release|Any CPU
1917
{7A789136-B210-452D-A16B-20B5D8CCFE76}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{8A06A423-244F-404F-AAD8-53DE2EE2AED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{8A06A423-244F-404F-AAD8-53DE2EE2AED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{8A06A423-244F-404F-AAD8-53DE2EE2AED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
23-
{8A06A423-244F-404F-AAD8-53DE2EE2AED7}.Release|Any CPU.Build.0 = Release|Any CPU
2418
EndGlobalSection
2519
GlobalSection(SolutionProperties) = preSolution
2620
HideSolutionNode = FALSE

DisplayRotation/Core/ApplicationSettings.cs

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using DisplayRotation.Internal;
21
using System;
32
using System.Drawing;
43
using System.Linq;
54
using System.Reflection;
65
using System.Windows;
6+
using System.Windows.Controls;
77
using System.Windows.Forms;
8+
using DisplayRotation.Internal;
9+
using Button = System.Windows.Controls.Button;
10+
using ContextMenu = System.Windows.Forms.ContextMenu;
11+
using MenuItem = System.Windows.Forms.MenuItem;
812

913
namespace DisplayRotation.Core
1014
{
@@ -14,15 +18,23 @@ public class ApplicationSettings : IApplicationSettings
1418
private NotifyIcon _ni;
1519
private readonly IActiveDevices _activeDevices;
1620
private readonly IRotateDisplay _rotateDisplay;
21+
private readonly IRotateButtonAndCanvas _rotateButtonAndCanvas;
1722

1823
/// <summary>
1924
/// </summary>
2025
/// <param name="mainWindow"></param>
2126
/// <param name="ni"></param>
2227
/// <param name="activeDevices"></param>
2328
/// <param name="rotateDisplay"></param>
24-
public ApplicationSettings(MainWindow mainWindow, NotifyIcon ni, IActiveDevices activeDevices,
25-
IRotateDisplay rotateDisplay)
29+
/// <param name="rotateButtonAndCanvas"></param>
30+
/// <exception cref="ArgumentNullException">
31+
/// <paramref name="mainWindow" /> is <see langword="null" />.
32+
/// <paramref name="ni" /> is <see langword="null" />.
33+
/// <paramref name="activeDevices" /> is <see langword="null" />.
34+
/// <paramref name="rotateDisplay" /> is <see langword="null" />.
35+
/// <paramref name="rotateButtonAndCanvas" /> is <see langword="null" />.
36+
/// </exception>
37+
public ApplicationSettings(MainWindow mainWindow, NotifyIcon ni, IActiveDevices activeDevices, IRotateDisplay rotateDisplay, IRotateButtonAndCanvas rotateButtonAndCanvas)
2638
{
2739
if (mainWindow == null)
2840
{
@@ -40,10 +52,15 @@ public ApplicationSettings(MainWindow mainWindow, NotifyIcon ni, IActiveDevices
4052
{
4153
throw new ArgumentNullException(nameof(rotateDisplay));
4254
}
55+
if (rotateButtonAndCanvas == null)
56+
{
57+
throw new ArgumentNullException(nameof(rotateButtonAndCanvas));
58+
}
4359
_mainWindow = mainWindow;
4460
_ni = ni;
4561
_activeDevices = activeDevices;
4662
_rotateDisplay = rotateDisplay;
63+
_rotateButtonAndCanvas = rotateButtonAndCanvas;
4764
}
4865

4966
/// <summary>
@@ -56,19 +73,17 @@ public void Run()
5673
StartMinimized();
5774
_ni.ContextMenu = NotifyIconContextMenu();
5875
_ni.DoubleClick += NotifyIcon_DoubleClick;
59-
//_ni.Click += (sender, args) => _ni.ShowBalloonTip(10);
6076
}
6177

6278
/// <summary>
6379
/// </summary>
6480
public void StartMinimized()
6581
{
6682
_ni = new NotifyIcon
67-
{
68-
Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location),
69-
//BalloonTipTitle = Resources.ApplicationSettings_StartMinimized_BalloonTipTitle,
70-
Visible = true
71-
};
83+
{
84+
Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location),
85+
Visible = true
86+
};
7287

7388
_mainWindow.Hide();
7489
}
@@ -79,34 +94,68 @@ private ContextMenu NotifyIconContextMenu()
7994

8095
foreach (var device in _activeDevices.Get().OrderBy(d => d.PositionX))
8196
{
97+
var currentButton = new Button();
98+
99+
foreach (Canvas canvas in _mainWindow.DisplayStackPanel.Children)
100+
{
101+
foreach (Button button in canvas.Children)
102+
{
103+
if (button.Name == $"ButtonDisplay{device.Id}")
104+
{
105+
currentButton = button;
106+
break;
107+
}
108+
}
109+
}
110+
82111
var parent = new MenuItem(device.Name);
83112

84113
//anticlockwise
85-
var anticlockwiseItem = new MenuItem("Hochformat 'anticlockwise'");
86-
anticlockwiseItem.Click += (sender, args) => _rotateDisplay.For(NativeMethods.Dmdo90, device.Id);
114+
var anticlockwiseItem = new MenuItem("Upright 'anticlockwise'");
115+
anticlockwiseItem.Click += (sender, args) =>
116+
{
117+
_rotateDisplay.For(NativeMethods.Dmdo90, device.Id);
118+
_rotateButtonAndCanvas.For(NativeMethods.Dmdo90, currentButton);
119+
_mainWindow.SetWindowMargins();
120+
};
87121

88122
//180
89-
var clockwiseItem = new MenuItem("Querformat (gedreht)");
90-
clockwiseItem.Click += (sender, args) => _rotateDisplay.For(NativeMethods.Dmdo180, device.Id);
123+
var clockwiseItem = new MenuItem("Landscape (rotated)");
124+
clockwiseItem.Click += (sender, args) =>
125+
{
126+
_rotateDisplay.For(NativeMethods.Dmdo180, device.Id);
127+
_rotateButtonAndCanvas.For(NativeMethods.Dmdo180, currentButton);
128+
_mainWindow.SetWindowMargins();
129+
};
91130

92131
//clockwise
93-
var mirrorItem = new MenuItem("Hochformat (gedreht) 'clockwise'");
94-
mirrorItem.Click += (sender, args) => _rotateDisplay.For(NativeMethods.Dmdo270, device.Id);
132+
var mirrorItem = new MenuItem("Upright 'clockwise'");
133+
mirrorItem.Click += (sender, args) =>
134+
{
135+
_rotateDisplay.For(NativeMethods.Dmdo270, device.Id);
136+
_rotateButtonAndCanvas.For(NativeMethods.Dmdo270, currentButton);
137+
_mainWindow.SetWindowMargins();
138+
};
95139

96140
//restore
97-
var restoreItem = new MenuItem("Querformat");
141+
var restoreItem = new MenuItem("Reset");
98142
restoreItem.DefaultItem = true;
99-
restoreItem.Click += (sender, args) => _rotateDisplay.For(NativeMethods.DmdoDefault, device.Id);
143+
restoreItem.Click += (sender, args) =>
144+
{
145+
_rotateDisplay.For(NativeMethods.DmdoDefault, device.Id);
146+
_rotateButtonAndCanvas.For(NativeMethods.DmdoDefault, currentButton);
147+
_mainWindow.SetWindowMargins();
148+
};
100149

101150
parent.MenuItems.AddRange(new[] { anticlockwiseItem, clockwiseItem, mirrorItem, restoreItem });
102151

103152
contextMenu.MenuItems.Add(parent);
104153
}
105154
contextMenu.MenuItems.Add("-");
106-
var restore = new MenuItem("Fenster öffnen");
155+
var restore = new MenuItem("Restore application");
107156
restore.Click += ContextMenuItemRestore_Click;
108157

109-
var close = new MenuItem("Beenden");
158+
var close = new MenuItem("Close application");
110159
close.Click += ContextMenuItemClose_Click;
111160

112161
contextMenu.MenuItems.AddRange(new[] { restore, close });
@@ -116,21 +165,18 @@ private ContextMenu NotifyIconContextMenu()
116165

117166
private void ContextMenuItemClose_Click(object sender, EventArgs e)
118167
{
119-
// Will Close Your Application
120168
_ni.Dispose();
121169
_mainWindow.Close();
122170
}
123171

124172
private void ContextMenuItemRestore_Click(object sender, EventArgs e)
125173
{
126-
//Will Restore Your Application
127174
_mainWindow.Show();
128175
_mainWindow.WindowState = WindowState.Normal;
129176
}
130177

131178
private void NotifyIcon_DoubleClick(object sender, EventArgs e)
132179
{
133-
//Will Restore Your Application
134180
_mainWindow.Show();
135181
_mainWindow.WindowState = WindowState.Normal;
136182
}

DisplayRotation/DisplayRotation.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<ApplicationManifest>app.manifest</ApplicationManifest>
4343
</PropertyGroup>
4444
<ItemGroup>
45+
<Reference Include="EvilBaschdi.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
46+
<HintPath>..\packages\EvilBaschdi.Core.1.0.0.3\lib\net462\EvilBaschdi.Core.dll</HintPath>
47+
<Private>True</Private>
48+
</Reference>
4549
<Reference Include="MahApps.Metro, Version=1.3.0.0, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
4650
<HintPath>..\packages\MahApps.Metro.1.3.0\lib\net45\MahApps.Metro.dll</HintPath>
4751
<Private>True</Private>
@@ -86,9 +90,9 @@
8690
<Compile Include="Internal\DisplayDevice.cs" />
8791
<Compile Include="Internal\DisplayDeviceStateFlags.cs" />
8892
<Compile Include="Internal\DisplaySettingsFlags.cs" />
93+
<Compile Include="Internal\IRotateButtonAndCanvas.cs" />
8994
<Compile Include="Internal\IRotateDisplay.cs" />
9095
<Compile Include="Internal\Pointl.cs" />
91-
<Compile Include="Internal\RotateDisplay.cs" />
9296
<Page Include="MainWindow.xaml">
9397
<Generator>MSBuild:Compile</Generator>
9498
<SubType>Designer</SubType>
@@ -99,6 +103,12 @@
99103
</Compile>
100104
<Compile Include="Internal\NativeMethods.cs" />
101105
<Compile Include="Internal\Devmode.cs" />
106+
<Compile Include="Internal\RotateButtonAndCanvas.cs">
107+
<DependentUpon>IRotateButtonAndCanvas.cs</DependentUpon>
108+
</Compile>
109+
<Compile Include="Internal\RotateDisplay.cs">
110+
<DependentUpon>IRotateDisplay.cs</DependentUpon>
111+
</Compile>
102112
<Compile Include="MainWindow.xaml.cs">
103113
<DependentUpon>MainWindow.xaml</DependentUpon>
104114
<SubType>Code</SubType>
@@ -147,12 +157,6 @@
147157
<ItemGroup>
148158
<Resource Include="Resources\Entypo-license.txt" />
149159
</ItemGroup>
150-
<ItemGroup>
151-
<ProjectReference Include="..\..\EvilBaschdi.Core\EvilBaschdi.Core\EvilBaschdi.Core.csproj">
152-
<Project>{8a06a423-244f-404f-aad8-53de2ee2aed7}</Project>
153-
<Name>EvilBaschdi.Core</Name>
154-
</ProjectReference>
155-
</ItemGroup>
156160
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
157161
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
158162
Other similar extension points exist, see Microsoft.Common.targets.

DisplayRotation/Internal/ActiveDevices.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public IEnumerable<DisplayHelper> Get()
1212
device.cb = Marshal.SizeOf(device);
1313

1414
var list = new List<DisplayHelper>();
15-
for(uint id = 0; NativeMethods.EnumDisplayDevices(null, id, ref device, 0); id++)
15+
for (uint id = 0; NativeMethods.EnumDisplayDevices(null, id, ref device, 0); id++)
1616
{
1717
device.cb = Marshal.SizeOf(device);
1818

@@ -22,28 +22,29 @@ public IEnumerable<DisplayHelper> Get()
2222

2323
device.cb = Marshal.SizeOf(device);
2424

25-
if(device.DeviceName.Trim().Length > 0)
25+
if (device.DeviceName.Trim().Length > 0)
2626
{
27-
//Devices.Text +=
28-
// $"{id}, {device.DeviceName}, {device.DeviceString}, {device.StateFlags}, {device.DeviceID}, {device.DeviceKey}, {device.cb} {Environment.NewLine}";
29-
3027
var helper = new DisplayHelper
31-
{
32-
Id = id,
33-
Name = device.DeviceString
34-
};
28+
{
29+
Id = id,
30+
Name = device.DeviceString
31+
};
3532

36-
foreach(var screen in Screen.AllScreens)
33+
foreach (var screen in Screen.AllScreens)
3734
{
38-
if(device.DeviceName.Contains(screen.DeviceName))
35+
if (device.DeviceName.Contains(screen.DeviceName))
3936
{
4037
var rectangle = screen.Bounds;
4138
helper.PositionX = rectangle.X;
39+
helper.PositionY = rectangle.Y;
40+
helper.Height = rectangle.Height;
41+
helper.Width = rectangle.Width;
4242
}
4343
}
4444
list.Add(helper);
4545
}
4646
}
47+
4748
return list;
4849
}
4950
}

DisplayRotation/Internal/DisplayDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace DisplayRotation.Internal
44
{
55
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
6-
internal struct DisplayDevice
6+
public struct DisplayDevice
77
{
88
[MarshalAs(UnmanagedType.U4)] public int cb;
99

DisplayRotation/Internal/DisplayDeviceStateFlags.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
namespace DisplayRotation.Internal
44
{
55
[Flags]
6-
internal enum DisplayDeviceStateFlags
6+
public enum DisplayDeviceStateFlags
77
{
88
AttachedToDesktop = 0x1,
99
MultiDriver = 0x2,
10-
1110
PrimaryDevice = 0x4,
12-
1311
MirroringDriver = 0x8,
14-
1512
VgaCompatible = 0x16,
16-
1713
Removable = 0x20,
18-
1914
ModesPruned = 0x8000000,
2015
Remote = 0x4000000,
2116
Disconnect = 0x2000000

DisplayRotation/Internal/DisplayHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ namespace DisplayRotation.Internal
33
public class DisplayHelper
44
{
55
public int PositionX { get; set; }
6+
public int PositionY { get; set; }
67
public uint Id { get; set; }
78
public string Name { get; set; }
9+
public int Height { get; set; }
10+
public int Width { get; set; }
811
}
912
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Windows.Controls;
2+
3+
namespace DisplayRotation.Internal
4+
{
5+
public interface IRotateButtonAndCanvas
6+
{
7+
void For(int rotation, Button button);
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace DisplayRotation.Internal
5+
{
6+
public class RotateButtonAndCanvas : IRotateButtonAndCanvas
7+
{
8+
public void For(int rotation, Button button)
9+
{
10+
var x = 10d;
11+
var w = 192d;
12+
var h = 108d;
13+
14+
switch (rotation)
15+
{
16+
case NativeMethods.Dmdo90:
17+
case NativeMethods.Dmdo270:
18+
button.Height = w;
19+
button.Width = h;
20+
((Canvas) button.Parent).Margin = new Thickness(x, 0, h, 0);
21+
break;
22+
23+
case NativeMethods.Dmdo180:
24+
case NativeMethods.DmdoDefault:
25+
26+
button.Height = h;
27+
button.Width = w;
28+
((Canvas) button.Parent).Margin = new Thickness(x, 0, w, 0);
29+
break;
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)