Skip to content

Commit

Permalink
Merge pull request #50 from andyvans/multiscreen-enhancements
Browse files Browse the repository at this point in the history
Multiscreen enhancements
  • Loading branch information
mika76 authored Jun 3, 2019
2 parents dbdc366 + 98cca6a commit 1558489
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 12 deletions.
23 changes: 17 additions & 6 deletions Mamesaver/Config/GeneralTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="clr-namespace:Mamesaver.Models.Extensions"
xmlns:models="clr-namespace:Mamesaver.Models.Configuration"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="800"
Background="White">
Expand All @@ -21,6 +23,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>

</Grid.RowDefinitions>
Expand Down Expand Up @@ -52,35 +55,43 @@
<!-- Options -->
<!-- Cloning -->
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Label VerticalAlignment="Center">Start MAME on:</Label>
<ComboBox Width="200" ItemsSource="{Binding Source={extensions:Enumeration {x:Type models:MamePrimaryScreen}}}"
DisplayMemberPath="Description"
SelectedValue="{Binding PrimaryScreen}"
SelectedValuePath="Value"/>
</StackPanel>

<StackPanel Grid.Row="4" Orientation="Horizontal" ToolTip="For optimal streaming quality, MAME should start on the highest resolution monitor">
<CheckBox IsChecked="{Binding CloneScreen}" VerticalContentAlignment="Center" Padding="0">
<Label Style="{StaticResource Inline}">Clone MAME to all monitors</Label>
<Label Style="{StaticResource Inline}">Stream MAME to other displays</Label>
</CheckBox>
</StackPanel>

<!-- Hoykeys -->
<StackPanel Grid.Row="4" Orientation="Horizontal">
<StackPanel Grid.Row="5" Orientation="Horizontal">
<CheckBox IsChecked="{Binding HotKeysEnabled}" VerticalContentAlignment="Center" Padding="0">
<Label Style="{StaticResource Inline}">Enable hotkeys</Label>
</CheckBox>
</StackPanel>

<!-- Advanced -->
<StackPanel Grid.Row="5" Margin="0,10,0,0">
<StackPanel Grid.Row="6" Margin="0,10,0,0">
<DockPanel Height="Auto">
<Label Style="{StaticResource Divider}" DockPanel.Dock="Left" Content="Advanced" />
<Separator Background="{DynamicResource {x:Static SystemColors.ScrollBarBrushKey}}" />
</DockPanel>
</StackPanel>

<!-- Imperfect emulation -->
<StackPanel Grid.Row="6" Orientation="Horizontal">
<StackPanel Grid.Row="7" Orientation="Horizontal">
<CheckBox IsChecked="{Binding IncludeImperfectEmulation}" VerticalContentAlignment="Center" Padding="0">
<Label Style="{StaticResource Inline}">Include games with imperfect emulation</Label>
</CheckBox>
</StackPanel>

<!-- Debug logging -->
<StackPanel Grid.Row="7" Orientation="Horizontal">
<StackPanel Grid.Row="8" Orientation="Horizontal">
<CheckBox IsChecked="{Binding DebugLogging}" VerticalContentAlignment="Center" Padding="0">
<Label Style="{StaticResource Inline}">Debug logging</Label>
</CheckBox>
Expand Down
11 changes: 11 additions & 0 deletions Mamesaver/Config/ViewModels/GeneralTab/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public bool CloneScreen
}
}

public MamePrimaryScreen PrimaryScreen
{
get => _settings.MamePrimaryScreen;
set
{
if (value == _settings.MamePrimaryScreen) return;
_settings.MamePrimaryScreen = value;
OnPropertyChanged();
}
}

/// <summary>
/// Time to run each game.
/// </summary>
Expand Down
24 changes: 19 additions & 5 deletions Mamesaver/MameOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void Run()
return;
}

// Find the best primary screen for MAME. As games are largely vertical and screens are wide, select the one with the greatest Y axis
var bestPrimaryScreen = Screen.AllScreens.OrderByDescending(screen => screen.Bounds.Height).First();
var primaryScreen = GetPrimaryScreen();

_screenManager.Initialise(_cancellationTokenSource);

Expand All @@ -94,12 +93,12 @@ public void Run()
_powerManager.Initialise();

// Initialise primary MAME screen
_gamePlayManager.Initialise(bestPrimaryScreen, _cancellationTokenSource);
_mameScreen.Initialise(bestPrimaryScreen);
_gamePlayManager.Initialise(primaryScreen, _cancellationTokenSource);
_mameScreen.Initialise(primaryScreen);

// Initialise all other screens
var clonedScreens = new List<BlankScreen>();
foreach (var otherScreen in Screen.AllScreens.Where(screen => !Equals(screen, bestPrimaryScreen)))
foreach (var otherScreen in Screen.AllScreens.Where(screen => !Equals(screen, primaryScreen)))
{
var blankScreen = _screenFactory.Create();
_screenManager.RegisterScreen(blankScreen);
Expand Down Expand Up @@ -134,6 +133,21 @@ public void Run()
}
}

/// <summary>
/// Get the primary screen to run MAME on.
/// </summary>
/// <returns></returns>
private Screen GetPrimaryScreen()
{
if (_settings.MamePrimaryScreen == MamePrimaryScreen.HighestResolution)
{
// Find the best primary screen for MAME.
// As games are largely vertical and screens are wide, select the one with the greatest Y axis
return Screen.AllScreens.OrderByDescending(screen => screen.Bounds.Height).First();
}
return Screen.PrimaryScreen;
}

/// <summary>
/// Stops the screensaver
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Mamesaver/Mamesaver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@
<Compile Include="MameExitCodes.cs" />
<Compile Include="MameScreen.cs" />
<Compile Include="Models\Configuration\AdvancedSettings.cs" />
<Compile Include="Models\Configuration\MamePrimaryScreen.cs" />
<Compile Include="Models\Configuration\FontSettings.cs" />
<Compile Include="Models\Configuration\GameList.cs" />
<Compile Include="Models\Configuration\InGameTitles.cs" />
<Compile Include="Models\Configuration\LayoutSettings.cs" />
<Compile Include="Models\Configuration\Settings.cs" />
<Compile Include="Models\Configuration\SplashScreen.cs" />
<Compile Include="Models\Extensions\EnumerableExtensions.cs" />
<Compile Include="Models\Extensions\EnumerationExtension.cs" />
<Compile Include="Models\Extensions\ExceptionExtensions.cs" />
<Compile Include="Models\Extensions\XmlExtensions.cs" />
<Compile Include="Models\Game.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Mamesaver/Models/Configuration/MamePrimaryScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel;

namespace Mamesaver.Models.Configuration
{
public enum MamePrimaryScreen
{
[Description("Highest resolution display")]
HighestResolution,

[Description("Primary display")]
WindowsPrimary
}
}
7 changes: 7 additions & 0 deletions Mamesaver/Models/Configuration/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public Settings()
HotKeys = true;
LayoutSettings = new LayoutSettings();
AdvancedSettings = new AdvancedSettings();
MamePrimaryScreen = MamePrimaryScreen.HighestResolution;
}

/// <summary>
Expand All @@ -45,6 +46,12 @@ public Settings()
[XmlElement("cloneScreen")]
public bool CloneScreen { get; set; }

/// <summary>
/// Which monitor should Mame run on
/// </summary>
[XmlElement("mameScreen")]
public MamePrimaryScreen MamePrimaryScreen { get; set; }

/// <summary>
/// Whether hot keys should be enabled to interact with screensaver.
/// </summary>
Expand Down
65 changes: 65 additions & 0 deletions Mamesaver/Models/Extensions/EnumerationExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Markup;

namespace Mamesaver.Models.Extensions
{
/// <summary>
/// Provide metadata about enumerations
/// </summary>
public class EnumerationExtension : MarkupExtension
{
private Type _enumType;

public EnumerationExtension(Type enumType)
{
EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType));
}

public Type EnumType
{
get => _enumType;
private set
{
if (_enumType == value) return;

var enumType = Nullable.GetUnderlyingType(value) ?? value;
if (enumType.IsEnum == false) throw new ArgumentException("Type must be an Enum");

_enumType = value;
}
}

public override object ProvideValue(IServiceProvider serviceProvider)
{
var enumValues = Enum.GetValues(EnumType);

return (
from object enumValue in enumValues
select new EnumerationMember
{
Value = enumValue,
Description = GetDescription(enumValue)
}).ToArray();
}

private string GetDescription(object enumValue)
{
var descriptionAttribute = EnumType
.GetField(enumValue.ToString())
.GetCustomAttributes(typeof(DescriptionAttribute), false)
.FirstOrDefault() as DescriptionAttribute;

return descriptionAttribute != null
? descriptionAttribute.Description
: enumValue.ToString();
}

public class EnumerationMember
{
public string Description { get; set; }
public object Value { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Other than those main settings, you can also:
* Set the command line options which are sent to MAME. I recommend leaving the `-skip_gameinfo` option.
* Enable and configure the splash screen with game information
* Enable and configure in-game game information
* Enable multi-monitor cloning
* Choose which display to start MAME on
* Enable streaming of MAME to other displays. For optimal streaming quality, MAME should start on the highest resolution monitor
* Include games with imperfect emulation
* Enable in-game hotkeys

Expand Down
Binary file modified Resources/SettingsPanel1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1558489

Please sign in to comment.